Skip to content

Instantly share code, notes, and snippets.

@fercreek
Created August 19, 2016 06:13
Show Gist options
  • Select an option

  • Save fercreek/82e4d1bed69ff695aeea02249af2f647 to your computer and use it in GitHub Desktop.

Select an option

Save fercreek/82e4d1bed69ff695aeea02249af2f647 to your computer and use it in GitHub Desktop.
/*
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) {
count = 0;
arr[0] = arr[0].split("").map(function(x){return x.toLowerCase();}).join("");
var status = arr[1].split("").every(function(e){
return arr[0].indexOf(e.toLowerCase()) >= 0 ? true:false;
});
return status;
}
mutation(["hello", "Hello"]);
// mutation(["hello", "hey"]) should return false.
// mutation(["hello", "Hello"]) should return true.
// mutation(["zyxwvutsrqponmlkjihgfedcba", "qrstu"]) should return true.
// mutation(["Mary", "Army"]) should return true.
// mutation(["Mary", "Aarmy"]) should return true.
// mutation(["Alien", "line"]) should return true.
// mutation(["floor", "for"]) should return true.
// mutation(["hello", "neo"]) should return false.
// mutation(["voodoo", "no"]) should return false.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment