Mutations Challenge Help324

Mutations Challenge Help324
0

#1

Tell us what’s happening:

Your code so far

function mutation(arr) {
  arr[0] = arr[0].toLowerCase();
  arr[1] = arr[1].toLowerCase();
  var arr2 = arr[0].split("");
  var arr3 = arr[1].split("");
  var count = 0;
  for (var i = 0; i < arr2.length; i++) {
    for (var j = 0; j < arr3.length; j++) {
      if (arr2[i] == arr3[j]) {
        count++;
      }
    }
  }
  if (count >= arr3.length) {
    return true;
  } else {
    return false;
  }
}

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

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36.

Link to the challenge:

Why does the final test not pass?


#2

In the final test of:

mutation([“voodoo”, “no”])

the following code inside your nested for loop:

      if (arr2[i] == arr3[j]) {
        count++;
      }

increments the count variable for each “o” in “voodoo”, so because count is 4 and arr3.length is 2, your solution returns true which is incorrect.


#3

Oh! Okay, Thanks so much @RandellDawson !