Tell us what’s happening:
I know there was a similar post regarding using .includes() on mutations, but I think my problem might be slightly different (or maybe I didn’t understand the hint). I also know there is a solution using .indexOf(), but I’m curious as to why this isn’t working.
I can’t figure out for the life of me, why my “if” statement would evaluate to “false” with these arguments. I did a console.log of arr1[i] in this instance and it returns “a” which is included in “Aliens”.
Basically, no matter what I enter for arguments, “arr0.includes(arr1[i])” always evaluates to “false”.
I think I’m fundamentally misunderstanding something, but I’ve been at this for hours, so time to ask for help!
Your code so far
function mutation(arr) {
// code to return lower case array//
var arr0 = arr.map(function (x) {
return x.toLowerCase();
});
//pop to remove second element from first//
var arr1 = arr0.pop();
// for loop to iterate over second array and evaluate against first array//
for (var i = 0; i < arr1.length; i++) {
// why does this evaluate to false? //
if (arr0.includes(arr1[i]) == false) {
return false;
}
}
return true;
}
mutation(["Alien", "line"]);
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:70.0) Gecko/20100101 Firefox/70.0
.
Challenge: Mutations
Link to the challenge:
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-algorithm-scripting/mutations