Data structures Mutation

Tell us what’s happening:
Describe your issue in detail here.
I think I make correct use ofArray.prototype.indexOf() but am still getting errors can someone explain to me what’s wrong with my code.

  **Your code so far**

function mutation(arr) {
let arr1 = arr[0].toLowerCase().split('');
let arr2 = arr[1].toLowerCase().split('');
for (let i = 0; i < arr1.length; i++) {
  // console.log(arr2.indexOf(arr1[i]))
  if (arr2.indexOf(arr1[i]) === -1 ){
    return false     
  return true


let ans = 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/92.0.4515.159 Safari/537.36

Challenge: Mutations

Link to the challenge:

You’re returning true inside of your loop. Return statements immediately stop your function.

You’ve got a few things going wrong here. The first thing I would suggest is to pick better names for your variables to help you keep straight which one you should be iterating through. Also, format your code properly with indentation as that will hopefully show something about the second return statement.

1 Like

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