.includes() method mutations

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

This expression will evaluate to either true or false, so you end up asking if arr0 includes true or false, which would only evaluate to true if arr0 has any true or false elements, but none of the test cases do.

What exactly are you wanting to check in the following if statement?

  if (arr0.includes(arr1[i]) == false) {

OK, I was trying to see if that statement is false, and if so to return false. I guess I misunderstood the method! Thanks!

Let’s say I have the following code:

const str = 'abcde';

If I want to check if str does not include the letter t, then I would write:

if (!str.includes('t')) {
  console.log('does not include the letter "t"');
}

Notice that exclamation point before the `str`?   That will negate a Boolean value.  So, since `str.includes('t')` evaluates to `false`, the `!` will change the if statement's condition to `true` and cause the if statement code block to execute.

Thank you! That gives me something to try later tonight! Thanks so much for your help!