July 3rd, 2020
Join this week code review organized by Corvid master,
Comment your code below(as per instruction) we will analyze provide you suggestion or refactored code that will be easy to read, to modify, and plenty of good practice.
We also welcome experience corvid forum members to share knowledge and expertise.
Instructions:
*1: FULL PAGE CODE is recommended
*2: Include database structure like Collection name & Field type (if you refer them in the code)
3: Is this a live site? If so, drop a link so, we can check the code.
4: Videos or Images for an explanation of what the code does is useful!
Marked * are required
Don’ts
1: Do NOT include any sensitive code (like passwords, secret key).
// try to rewrite it as xxx if it's used inside the code
const key = "XXX-XXX";
2: Asking any questions unrelated to code review or corvid
3: Screenshot the code and not pasting the code in text format
4: Code that was not working before and asking to fix (Please create a new post in the community, This Post is dedicated to improve your current working code)
Comment not related to refactoring for the code will be get deleted to organize
Notes
2 Likes
Hello again 
if you are bored at the moment, i have a little job for you 
a have a code which has to be improved if there are any improvment possibilities.
This is the whole code…
import wixData from 'wix-data';
$w.onReady(function () { });
export function button1_click(event) {SEARCH()}
function SEARCH (parameter) {
var wordCounter = 0
let myText = $w('#TXTinput').text
$w('#TXToutput').text = ""
var searchValue = $w('#input1').value//.toLowerCase();
var searchWordLength = searchValue.length
var searchWords = myText.split(' ');
var searchWords1 = []
var searchWords2 = []
var searchWords3 = []
$w('#wordLength').value=searchWordLength
console.log(searchWords)
for (let i=0; i < searchWords.length; i++) {
let mySearchWord=searchWords[i]
console.log(mySearchWord)
if (mySearchWord.slice(0,searchWordLength)==searchValue || mySearchWord.slice(0,searchWordLength)==searchValue.toLowerCase()) {console.log("YES-1")
if (mySearchWord.charCodeAt(searchWordLength+1) >=65 && mySearchWord.charCodeAt(searchWordLength+1) <=90) {}
else if (mySearchWord.charCodeAt(searchWordLength+1) >=98 && mySearchWord.charCodeAt(searchWordLength+1) <=122) {}
else if (mySearchWord.charCodeAt(searchWordLength+1) >=192 && mySearchWord.charCodeAt(searchWordLength+1) <=255) {}
else {console.log("FOUND-1"), searchWords1.push(mySearchWord), wordCounter++}
}
if (mySearchWord.slice(1,searchWordLength+1)==searchValue || mySearchWord.slice(1,searchWordLength+1)==searchValue.toLowerCase()) {console.log("YES-2")
console.log(mySearchWord.charCodeAt(1))
if (mySearchWord.charCodeAt(0) >=65 && mySearchWord.charCodeAt(0) <=90) {console.log("1")}
else if (mySearchWord.charCodeAt(0) >=98 && mySearchWord.charCodeAt(0) <=122) {console.log("2")}
else if (mySearchWord.charCodeAt(0) >=192 && mySearchWord.charCodeAt(0) <=255) {console.log("3")}
else {console.log("FOUND-2"), searchWords2.push(mySearchWord), wordCounter++}
}
}
searchWords3 = searchWords1 + searchWords2
console.log("---- 1 ----")
console.log(searchWords1)
console.log("---- 2 ----")
console.log(searchWords2)
console.log("---- 3 ----")
console.log(searchWords3)
$w('#OUTPUTfoundterms').value=wordCounter
$w('#TXTresults').text=searchWords3
$w('#TXToutput').text = searchWords.toString()
}
Here you can see the live-example…
https://russian-dima.wixsite.com/meinewebsite/search-box
What was/is the aim of this little project?
-
A kind of “text-analyse-box” which searches for inique full words.
-
Which does not matches word-fragments (not same behaviour as when you would using —> “contains” or “eq” when searching in data-collections/datasets, for example.
-
If possible make the code work 100%, because right now it does not find all words 100% (for example it does not find the word “Game” nad not all words of “puppy”, in the live example.)
Would be great if this could be fixed 
And additional here the forum-post, belongs to this little project…
/*
Hey dima, Hope you are doing well
i think the best way IMO is to use external lib
to search the word, I have used fuzzy search before
I will recommend that
https://www.npmjs.com/package/fuzzy-search
I have refactor the code and you just compute onetime and store the value
e.g:
const sliceWord = mySearchWord.slice(0, searchWordLength);
and use `let` instead of `var`
and don't use `PARAMS`
*/
export function button1_click() {
SEARCH();
}
function SEARCH() {
let wordCounter = 0;
let myText = $w("#TXTinput").text;
$w("#TXToutput").text = "";
let searchValue = $w("#input1").value; //.toLowerCase();
let searchWordLength = searchValue.length;
let searchWords = myText.split(" ");
let searchWords1 = [];
let searchWords2 = [];
let searchWords3 = [];
$w("#wordLength").value = searchWordLength;
console.log(searchWords);
for (let i = 0; i < searchWords.length; i++) {
let mySearchWord = searchWords[i];
console.log(mySearchWord);
const sliceWord = mySearchWord.slice(0, searchWordLength);
const charCodeAt = mySearchWord.charCodeAt(searchWordLength + 1);
const sliveWord1 = mySearchWord.slice(1, searchWordLength + 1);
const charCode0 = mySearchWord.charCodeAt(0);
if (sliceWord === searchValue || sliceWord === searchValue.toLowerCase()) {
console.log("YES-1");
if (charCodeAt >= 65 && charCodeAt <= 90) {
} else if (charCodeAt >= 98 && charCodeAt <= 122) {
} else if (charCodeAt >= 192 && charCodeAt <= 255) {
} else {
console.log("FOUND-1");
searchWords1.push(mySearchWord), wordCounter++;
}
}
if (sliveWord1 == searchValue || sliveWord1 == searchValue.toLowerCase()) {
console.log("YES-2");
console.log(mySearchWord.charCodeAt(1));
if (charCode0 >= 65 && charCode0 <= 90) {
console.log("1");
} else if (charCode0 >= 98 && charCode0 <= 122) {
console.log("2");
} else if (charCode0 >= 192 && charCode0 <= 255) {
console.log("3");
} else {
console.log("FOUND-2"), searchWords2.push(mySearchWord), wordCounter++;
}
}
}
searchWords3 = searchWords1 + searchWords2;
console.log("---- 1 ----");
console.log(searchWords1);
console.log("---- 2 ----");
console.log(searchWords2);
console.log("---- 3 ----");
console.log(searchWords3);
$w("#OUTPUTfoundterms").value = wordCounter;
$w("#TXTresults").text = searchWords3;
$w("#TXToutput").text = searchWords.toString();
}