Basic Algorithm Scripting - Mutations

Tell us what’s happening:
Describe your issue in detail here.

  **Your code so far**
function mutation(arr) {
let arr1 = arr[0].toLowerCase();
let arr2 = arr[1].toLowerCase();
for(let i = 0; i < arr2.length; i++){
  if(arr1.indexOf(arr2[i]) < 0){
    return false;
  }
    return true;
}
}
mutation(["hello", "hey"]);


  **Your browser information:**

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

Challenge: Basic Algorithm Scripting - Mutations

Link to the challenge:

Only the hello-hey test is not passing, what am I missing here?

A return statement will exit the surrounding function. It ceases to run. It’s over. Finito. Add this just inside your for loop:

console.log(arr1, arr2[i])

Watch what is happening. Do you understand why?

1 Like

Thank you, this helped me see the problem and turned out the solution was quite easy :smiley:

1 Like

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