Skip to content

Latest commit

 

History

History
32 lines (28 loc) · 698 Bytes

File metadata and controls

32 lines (28 loc) · 698 Bytes

console.log(isInDict("a")); // true console.log(isInDict("cr")); // true console.log(isInDict("br")); // false

const arr = ["cat", "car", "bar"];
function isInDict(word) {
  for (let i = 0; i < arr.length; i++) {
    let currentWord = arr[i];
    if (currentWord.length !== word.length) {
      continue;
    }
    let isMatch = true;
    for (let j = 0; j < currentWord.length; j++) {
      if (word[j] !== "*" && word[j] !== currentWord[j]) {
        isMatch = false;
        break;
      }
    }
    if (isMatch) {
      return true;
    }
  }
  return false;
}

console.log(isInDict("*a*")); // true
console.log(isInDict("c*r")); // true
console.log(isInDict("br*")); // false