In the code below, I am looping through the 'words' array and comparing it to the query. It should return false if they are different and if the length is not the same.
For some reason, when called, the 'isMatch' function is not returning true inside the if statement of the 'isMember' function and is always returning false. What am I missing?
const words = ['foo', 'bar', 'baz']
const isMember = (words, query) =>{
words.forEach(w => {
if(isMatch(w, query)){
return true
}
})
return false
}
function isMatch(word, query){
if(word.length !== query.length){
return false
}
for(let i = 0 ; i < word.length ; i++){
if(word[i] !== query[i] && query[i] !== '*'){
return false
}
}
return true
}
console.log(isMember(words, 'foo')) /*expected outcome: true*/
console.log(isMember(words, 'hello')) /*expected outcome: false*/
console.log(isMember(words, 'f*o')) /*expected outcome: true*/
console.log(isMember(words, '**')) /*expected outcome: false*/
console.log(isMember(words, '*az')) /*expected outcome: true*/