Help understanding the code

Help understanding the code
0.0 0

#1

Well, I was trying to solve the challenge and came up with solution below. For some reason, which I’ve not found yet because of lack of the knowledge I guess, my code doesn’t work …for instance it doesn’t give me the right result when I input this “mutation([“Alien”, “line”])” or that “mutation([“hello”, “heewqeweyqw”]);” so far I know that the problem is in the line below:

arr[0].indexOf(arr[1][j].split('')) >= 0

I tested this part of the code and it works well when I replace j with the number, but it doesn’t work when I try to implement it in my code. Compiler tells me “Cannot read property ‘split’ of undefined” and by undefined it means the variable j (at least I think so), but as far as I understand I defined j in the for loop and it should work… I will be glad to hear some advice.
P.S. I don’t need another solution. I want to figure out why mine doesn’t work. I may seem illiterate, sorry for that. English isn’t my native language and I’ve been studying it for only 2 years so far. The main language is Russian.
This is my code:

function mutation(arr) {
  let i = 0;
  for (var j = 0; j <= arr[1].split('').length; j++) {
    if (arr[0].indexOf(arr[1][j].split('')) >= 0) {
    i++;
    }
  }
  return i < arr[1].split('').length ? false : true;
}

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

This is the error I always get:

TypeError: Cannot read property 'split' of undefined
    at mutation:4:34
    at eval:11:1
    at eval
    at new Promise

#2
    if (arr[0].indexOf(arr[1][j].split('')) >= 0) {

I don’t have time to solve your code, but I think your error is with this line. arr is an array of strings, so arr[1][j] would be referring to a character in that string. Characters don’t have a split method - that’s for strings.


#3

You have an undefined element in your arr variable.

HINT: Because indexes start at 0, but length gives the whole length of the string.
Your problem is actually in line #3.

solution #1: (click to unblur)

or solution #2


#4

Thank you so much, I got it before I even looked up in your solution :smiley: You definitely made my day.