I’m trying to figure out why my code is not giving the right output.
My input shouldn’t be contained within the array elements.
I found an easy way to solve it with regex, so I am not using regex for that one.
Please, break down my code, and tell me what is the problem with the code.
function checkInput(input, words) {
var arr = input.toLowerCase().split(" ");
var i, j;
var matches = 0;
for (i = 0; i < arr.length; i++) {
for (j = 0; j < words.length; j++) {
if (arr[i] != words[j]) {
matches++;
}
}
}
if (matches > 0) {
return true;
} else {
return false;
}
};
console.log(checkInput("Move an array element from one array", ["from"])); // should be false
console.log(checkInput("Move an array element from one array", ["elem"])); // should be true
trueiff no element of yourwordsarray is a word in yourinputstring, right?