Mutations below code not working....kindly explain

Mutations below code not working....kindly explain
0

#1

Tell us what’s happening:
below code not working …mutation([“hello”, “hey”]); return true;

Your code so far

function mutation(arr) {
  
  var first= arr[1].toLowerCase();
  var last=arr[0].toLowerCase();
  for(var i= 0;i<first.length;i++){
if(last.indexOf(first[i])===-1)
  return false;

return true;



}

}


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

Your browser information:

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

Link to the challenge:


#2

@jasveer-code,
I have to say this at the start, you need to make your code more readable. This is a BIG reason for why you don’'t understand what is happening.
If you have code that is nested inside a block, indent it, so you can easily understand what is inside the nested block and what isn’t.

Below is your edited code :

function mutation(arr) {
  
  var first= arr[1].toLowerCase();
  var last=arr[0].toLowerCase();
  for(var i= 0;i<first.length;i++){
             if(last.indexOf(first[i])===-1)
                return false;
            return true;
        }
}

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

Always open up a pair of curly brackets when using an if clause. Can you see where your problem is now?


#3

@TomerPacific
thank you! sir… I appreciate you taking the time to help and I will take care of this onwards.