Bonfire Mutations [stuck]

Hi

I’m hit a wall on this one: I assumed all my expressions would satsify all the prompts on the side. The only giving me trouble is the ["hello,“hey”] scenario… I’ve uploaded a link with my code. Please advise me on what I should be focusing on. No need to give the answer.

Thank you :slight_smile:

Thanks sir! Duly noted and appreciate the input on cleaning up the work.

Thanks so much for the advice on cleaning the code. I realized after removing the clutter, I was missing something important with my if statements. This method seemed to work! Take a look and let me know if there’s anything I can do to lean out the process even more.

function mutation(arr) {

var fst = arr[0].slice().toLowerCase();

var snd = arr[1].slice().toLowerCase();

var crct = [];
var wrng = [];

for (var i =0; i < snd.length; i++) {

if (fst.indexOf(snd[i]) !== -1){

 crct.push(snd[i]);

}// end of if statement

else if (fst.indexOf(snd[i]) !== 0){

 wrng.push(snd[i]);

}//end of else if statement

}//end of for loop

if (fst.indexOf(wrng) !== 0){

return false;

}// end of if statement

else if (fst.indexOf(wrng) !== -1){

return true;

}//end of else if

}//end of function

mutation([“zyxwvutsrqponmlkjihgfedcba”, “qrstu”]);

I used arrays for an unusual solution. This function will return true or false followed by an array representing the second parameter. It checks if that array contains a zero. Any zero represents an unmatched letter.

[details=My solution (spoiler)]

function mutation(arr) {
  /* Iterate through 2nd string one character at a time to see how many times each 
character is present in the 1st string */
  var z = [];
  for ( var i = 0; i < arr[1].length; i++ ) {
    z.push(0); //create an array of zeros of length of 2nd string 
    for ( var j = 0; j < arr[0].length; j++ ) {
      var x = arr[0][j];
      var y = new RegExp(x, 'i');  //create RegExp to ignore Case
        if (arr[1][i].match(y)) {
          z[i]++;
      }
    }
  }
  var checkForZero = function(isZero) {
    return isZero === 0;
  };
if (z.find(checkForZero) === 0) { 
  return false + ". array z is [" + z + "]";
}
else return true + ". array z is [" + z + "]";

}
mutation(["hello", "hey"]);
mutation(["zyxwvutsrqponmlkjihgfedcba", "qrstu"]);
```[/details]

thanks for the tips @rmdawson71.
I was pretty happy with this one but obviously still a newbie with much to learn.

1 Like

I’m with you on that! Glad you figured it out :slight_smile:

1 Like

I think that’ll be something I can try to do after solving - which is to see if I cut anything out unnecessary.

Thanks again!