Mutations help needed

Mutations help needed
0.0 0

#1

Tell us what’s happening:
Everything is returning true and i can’t figure out why

Your code so far


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

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

Your browser information:

User Agent is: Mozilla/5.0 (X11; CrOS x86_64 10452.99.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.203 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-algorithm-scripting/mutations


#2

The = is an assigment operator, not a comparison one (== or ===).

It seems that the assigment that you put in the if condition evaluates as true, so the execution goes into the if branch that returns true.


#3

I think you forgot to define the seperator for the split also. It should be given “” as the input in order to split by character (which I think is what you wanted).
This is the documentation explaining this:
https://www.w3schools.com/jsref/jsref_split.asp


#4

Agh!! Thank you so much! The solution is always so simple in hindsight!!


#5

Yes i did!! Thank you!! That helped a lot!!