# Doubt about the "Mutations" challenge on the Basic Algorithm Scripting solution

Hello ! I have a little doubt about the challenge “Mutations” on the Basic Algorithm Scripting course, if anyone can help me clarify it.

The challenge was :
Return `true` if the string in the first element of the array contains all of the letters of the string in the second element of the array.

For example, `["hello", "Hello"]`, should return `true` because all of the letters in the second string are present in the first, ignoring case.

The arguments `["hello", "hey"]` should return `false` because the string `hello` does not contain a `y`.

Lastly, `["Alien", "line"]`, should return `true` because all of the letters in `line` are present in `Alien`.

``````function mutation(arr) {
return arr;
}

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

Then I was struggling the solution trying to figure it out, then I realized I needed to separate each arr index into other arrays for each letter on the strings ‘hello’ and ‘hey’ with the .split( ) function. Then I look into the solution number 1 and see this:

``````function mutation(arr) {
let test = arr[1].toLowerCase()
let target = arr[0].toLowerCase()
for (let i = 0; i < test.length; i ++) {
if (target.indexOf(test[i]) < 0) {
return false
}
}
return true
}
mutation(["hello", "hey"]);
``````

My question is. Why isn’t .split() method used to separate the letters on each string and then comparate them on the for loop? How is the for loop able to comparate each letter on the string (test) and (target) if we are using the index [i]?
My apologies if I explain myself bad, hope someone understand my concern and would help me understanding how does it work.

Thank you so much for that ! I was not getting why the code was working. Awesome

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.