Mutations needs HELP

I’ve been stuck on this one for a little while. Challenge asks me to see if param#2 letters in string are found in param#1 (not in any order). What I’m attempting to do here is cycle it through a for loop, with the loop running [i] through each indexable slot in param2, and checking them against the indexes in param1 for a match. If statement says that if true then return “true” if not “false”. I know im doing something wrong but not sure which thing or things are wrong.

Your code so far

    function mutation(arr) {
    for (var i = 0; i < arr[0].length; i++) {
    arr[0].indexOf(arr[1][i]);
  
     if (arr[0].indexOf(arr[1][i]) !== -1) {
      return "true";
      }}
      return "false";
      }
 mutation(["hello", "hey"]);

Your browser information:

Your Browser User Agent is: ```Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:54.0) Gecko/20100101 Firefox/54.0.1 Waterfox/54.0.1

Link to the challenge:

As soon as a return statement is hit, execution stops and the function is exited. You are returning true if the first letter is found.

1 Like

Feel like I’m overthinking this. Maybe I should store results .push’ed into a variable? Then compare that one to the param0? I was thinking of doing this but that would bring me to where I started.

I think I figured out a lot of my problem. This site will tell me that my method is not a function. Well it should be. It’s a method, therefore you could say it’s a function right? (May be wrong there but maybe not). So alot of my problem is just that I’m new (i’m an electrician and I’ve been coding for a month or two but I really think it comes natural). For instance, just lack of familiarity with certain things ( I realized I was trying to use .push to populate an empty string). It kept saying “not a function”, which got me nowhere. Then I changed my variable to be pushed to an empty ARRAY and it worked fine. I think I will get the hang of this, and I never give up. Thank you all for your help and when I finish this I will post my results.

Ok. I think it’s just syntax this time. I’ve went through and re-did my code based on rmdawson71’s algorithm logic. What I’ve come up with, if you individually enter in the test parameters, will fntion properly. For some reason it wont pass any of the tests when you “run tests”. I think I’ve either got it and its hung up on something minor, or something worse is wrong. What do you think? I do acknowledge I was doing a few things pretty seriously wrong before.

OOPS here is my code:

function mutation(arr) {
  var cuddler = [];
  var wiggler = [];
  var potato = [];

  for (var j = 0; j < arr[0].length; j++) {

    wiggler.push(arr[0][j].toLowerCase());
  }

  for (var q = 0; q < arr[1].length; q++) {

    potato.push(arr[1][q].toLowerCase());
  }

  for (var i = 0; i < potato.length; i++) {
    wiggler.indexOf(potato[i]);


    if (wiggler.indexOf(potato[i]) == -1) {
      cuddler.push(potato[i]);
      return "false";

    }
  }
  return "true";
}
mutation(["voodoo", "no"]);

Your first solution was actually very close. You were returning true as soon as you found a matching letter and only returning false after checking every letter. What you want to do is return false as soon as you hit a letter that isn’t found and only return true if you make it through the whole string.

I went back to that version. I changed the logic around so it matches what you said. Still getting stuck on the fact that this challenge is not case sensitive. I didn’t even see that part untill later :smile: .In the second version of my code I was able to reconcile that. Ill put them together an see what happens

I got it! Knew it was something simple. Thanks you guys for all the help. I’m getting a lot better with practice. I will read up on the backticks.

Thanks again. I will work on my presentation. Appreciate you letting me know.