Skip to content

Instantly share code, notes, and snippets.

@Jacob-Bass
Last active January 25, 2016 01:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jacob-Bass/cbe2576e688884aa31fa to your computer and use it in GitHub Desktop.
Save Jacob-Bass/cbe2576e688884aa31fa to your computer and use it in GitHub Desktop.
FreeCodeCamp "Mutations" solution
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.
For example, ["hello", "Hello"], should return true because all of the letters in the second string are present in the first, ignoring case.
The arguments ["hello", "hey"] should return false because the string "hello" does not contain a "y".
Lastly, ["Alien", "line"], should return true because all of the letters in "line" are present in "Alien".
function mutation(arr) {
var y = [arr[0].toLowerCase(),arr[1].toLowerCase()];
var x = y[1].split("");
var ver;
for (var i=0;i<x.length;i++){
if (y[0].indexOf(x[i])>=0){
ver=true;
}else if(y[0].indexOf(x[i])<0){
ver=false;
break;
}
}
switch(ver){
case true:
return true;
case false:
return false;
}
}
mutation(["floor", "for"]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment