Mutating Words
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.
by Susanna You
JavaScript
function mutation(arr) {
var arr0 = arr[0].toLowerCase(); //making sure the strings are lower case.
var arr1 = arr[1].toLowerCase();
for (var i = 0; i < arr1.length; i++) { // 1st looping thru arr1
var check = arr0.indexOf(arr1[i]); // setting a var "check" to see if arr1[i] (a letter) is in an indexOf arr0
if (check === -1) { // checking if "check" is === -1 (means if this doesn't exist indexOf returns -1).
console.log(false);
}
}
console.log(true);
}
mutation(["hello", "hey"]); //returns false
mutation(["hello", "Hello"]); //returns true
mutation(["zyxwvutsrqponmlkjihgfedcba", "qrstu"]); //returns true
mutation(["Mary", "Army"]); //returns true;
mutation(["Mary", "Aarmy"]); //returns true;
mutation(["Alien", "line"]); //returns true;
mutation(["floor", "for"]); //returns true;
mutation(["hello", "neo"]); //returns false;