Mutations code always returns true

Mutations code always returns true


Can anyone help me out? I pass all the True test cases, but none of the false cases.

function mutation(arr) {

  let word1 = arr[0].toLowerCase();
  let word2 = arr[1].toLowerCase().split("");

    if(word1.indexOf(i) < 0)
      return false;

 return true;

mutation(["hello", "hey"]);


Unfortunately, the return inside your forEach function does not exit the main function. For now, maybe stick with a basic for loop or a for of loop?

Since the forEach will complete the entire iteration of the array wordw, one option is the create a flag variable (let’s call it found) which would start with the value true (we would assume we are going to find all the letters). If the if statement evaluates to true, you would assign false to the found variable.


Got it, thanks! @randelldawson I tried to be a little fancy with forEach. I guess I need to stick to the basics, lol.


You can still use forEach by using the Boolean variable as I mentioned above. Sometimes, we just have to work within the constraints of the language and it’s built-in functions.