I hate for loops so this is a less verbose solution to traverse objects. It was unnecessary to convert the first index of the array into a string if comparing characters within the second index.
var strOne = arr[0].toLowerCase(); // first index of array to lowercase
var strTwo = arr[1].toLowerCase().split(""); // second index to lowercase, then split to an array
``console.log(strTwo); // output is ["h", "e","l"]
return strTwo.every(function(chr) { // every() executes a callback until it returns a false or true if all elements are present.
``return strOne.indexOf(chr) !== -1; //indexOf returns false if the value to search is not present.
}); } console.log(mutation(["hello", "Hel"]));
I hate
forloops so this is a less verbose solution to traverse objects. It was unnecessary to convert the first index of the array into a string if comparing characters within the second index.var strOne = arr[0].toLowerCase(); // first index of array to lowercase
var strTwo = arr[1].toLowerCase().split(""); // second index to lowercase, then split to an array
``console.log(strTwo); // output is ["h", "e","l"]
return strTwo.every(function(chr) { // every() executes a callback until it returns a false or true if all elements are present.
``return strOne.indexOf(chr) !== -1; //indexOf returns false if the value to search is not present.
}); } console.log(mutation(["hello", "Hel"]));