Basic Algorithm Scripting - Mutations

My code only can check the first element, but it is the same as the answer when I compare it with the answer. Did anyone know why? :pray:

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

console.log(mutation(["helLo", "hy"]))

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ Safari/537.36

Challenge: Basic Algorithm Scripting - Mutations

Link to the challenge:

arrl2.length>=i this is one the issue of your code. This condition is always true so technically this is an infinite loop, but due to the return true statement inside it, the loop will terminate prematurely.

The other one is the location of your return true statement. This must be executed if the loop terminates without returning false.

1 Like

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