Exercise Mutations

Exercise Mutations
0

#1

Tell us what’s happening:

On the console its returning false on this specific case just as I wanted, but its not getting accepted because its saying on those checkboxes in the bottom of the page that its not returning false. :confused:
I`m quite confused.
pls, can someont hep??
Your code so far

function mutation(arr) {
  var aux = "";
  for(var i =0; i < arr[0].length; i++)
    hash[(arr[0][i]).toLowerCase()] = 1;
  
  for(var j=0; j < arr[1].length; j++)
    if(!hash.hasOwnProperty((arr[1][j]).toLowerCase()))
      return false;
  
  return true;
}  
var hash = {};


mutation(["vodo", "no"]);

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:57.0) Gecko/20100101 Firefox/57.0.

Link to the challenge:


#2

You need to move the following variable initialization to be inside the function.

var hash = {};

Why? Because the FCC tests are ran sequentially and any global variables will retain their value between each execution of the tests. So, if you leave the global variable, then hash will keep growing and eventually affect the results of the other tests. Keeping it inside the function, makes sure it gets reset to an empty object during each test.

After the test mutation([“zyxwvutsrqponmlkjihgfedcba”, “qrstu”]); executes, hash has all the letters as properties, so, all the remaining tests return true. The problem is, the last two should return false.


#3

Thank you so much :smiley: