Basic Algorithm Scripting - Mutations

Why my code is not working.

This is the challenge:
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.

Your code so far

function mutation(arr) {
  let elem1 = arr[0].toLowerCase().split("");
  let elem2 = arr[1].toLowerCase().split("");

  

  for(let i = 0; i < arr.length; i++) {
    if(elem1.indexOf(elem2[i]) < 0) {
      return false
    }
  }
  return true;
}

console.log(mutation(["hello", "hey"]));

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/110.0

Challenge: Basic Algorithm Scripting - Mutations

Link to the challenge:

This doesn’t seem right.

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