# Basic Algorithm Scripting : Mutations : have to convert to Array? [solved]

Basic Algorithm Scripting : Mutations : have to convert to Array? [solved]
0

#1

I’m currently stuck at this challenge, my solution is as follows :

``````function mutation(arr) {
arr[0].toLowerCase();arr[1].toLowerCase();
for(let i=0; i<arr[1].length; i++){
if(arr[0].indexOf(arr[1].charAt(i)) < 0){return false;}
}
return true;
}

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

I don’t see any error in this, but the curriculum does not let me pass the challenge. I have a peek at ‘Get a hint’ which suggested something like converting the string to array, but do i have to?

#2

Your solution is case-sensitive.

#3

No, the first thing i do is convert all the element to lower case, pay attention to the first line below `function mutation(arr)`

#4

`str.toLowerCase()`
toLowerCase() does not affect the value of the string str itself.

#5

You are attempting to, but it isn’t doing what you think it is. Look at the documentation for `toLowerCase()`.

(Recall that strings are immutable.)

#6

Ah yes, thank you. Solved.

#7
``````var test = arr[0].toLowerCase();
var newTest = arr[1].toLowerCase();
for(var i = 0; i < newTest.length; i++){
if(test.indexOf(newTest[i]) > 0){
return true
}
return false
}

}
``````

this is my code so far, all tests passed except 2 ones, one where is “hello” second where is “floor” = “for”???

why it didnt work??

#8

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make easier to read.

See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (`</>`) will also add backticks around text.

Note: Backticks are not single quotes.

#9
``````            for(var i = 0; i < newTest.length; i++){
if(test.indexOf(newTest[i]) > 0){
return true
}
return false
}
``````

this loop always stops at the first iteration; when the `return` statement is executed the loop stops iterating. in this way you are checking only the first letter, and if for the first letter is true it doesn’t mean it is true for the others. Try in an other way