Ive throwen everything but the toaster at this....i could really use a hint

Tell us what’s happening:
i cant get the last array to pass

Your code so far

function mutation(arr) {
let first = arr[0].toLowerCase().split('');
let sec = arr[1].toLowerCase().split('');
let track = [];

for (let i = 0; i < sec.length; i++) { 
  for (let j = 0; j < first.length; j++) { 
    if (sec[i] === first[j] &&
    !track.includes(sec[i]) &&
if (track.join('') === sec.join('') || 
arr[1].toLowerCase() === arr[0].toLowerCase())
  return true;
  return false;

console.log(mutation(["Mary", "Aarmy"]));

Your browser information:

User Agent is: Mozilla/5.0 (X11; CrOS x86_64 13020.55.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.77 Safari/537.36.

Challenge: Mutations

Link to the challenge:

I think you should try to simplify your function body a little. The instructions say:

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. (ignoring case).

The first hint is that you only need to go through the characters in the second element of the array passed into the function. Right now you have nested for loops which are going through both strings passed in. You only need to go through the characters in the second string and check that each one is in the first string.

The second hint is that you don’t need to convert these to arrays using split(). You can iterate through a string just like you can iterate through an array. So the first character in a string str can be accessed as str[0], the second character as str[1], etc…

The third hint is that you definitely do not need nested for loops to do this. You should only have one loop and it should go through the second string.

Hopefully this is enough to steer you in the right direction.

1 Like