Mutations- Trying to solve it using arrays (solved)

Tell us what’s happening:
Hi there!

I already solved this problem while manipulating in strings. I was wondering/trying to see if I could get it to work in arrays.

Steps:

  1. Create a newstr and lowercase all of them
  2. Take the entire string and put it into a newarray using split
    3)Run a for loop based on original entry arr[0] and the length of our newarray
  3. Use indexOf on newarray to find if any -1 returns (I think this line is wrong in actual code, also cause it searches the entire array and I can’t search a portion of it)
  4. If -1 returns, then return False
  5. If all pass, return True

Any help would be great!
Your code so far

function mutation(arr) {

 var newstr=arr.join('').toLowerCase();
  var newarr = newstr.split('');

for (i = arr[0].length;i<newarr.length;i++){
  if (newarr.indexOf(newarr[i])==-1){
    return false;
}
      return true;
}
}

  


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

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:57.0) Gecko/20100101 Firefox/57.0.

Link to the challenge:
https://www.freecodecamp.org/challenges/mutations

Hi Randell!

Thanks for going through each of my steps line by line, really shows and helps how my logic/code was flawed.

I understand your concern about #1 because my original solution (same as one shown in tips), just wanted to see and ask about doing it in one array. But I guess given the tools that we have (and maybe logic wise), it is prone to errors and better off as model solution.

I finally understand why I think the for loops are incorrect as you have mentioned. I do realize the True was written incorrectly, but did not know return exits the loop, I thought it just kept going. Which is why when I wrote it on paper, it made sense to me but not as output.

Thank you again!