DavidSzczesniak
10/28/2017 - 11:46 PM

Check strings for similarity with indexOf

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.

function mutation(arr) {
  // Turn both inputs lower case, ignoring case completely
  var word = arr[0].toLowerCase();
  var word2 = arr[1].toLowerCase();
  
  for(var i = 0; i < word2.length; i++) {
    // Check word's contents against those of word2, by individual letter. If indexOf returns -1, return false
    if (word.indexOf(word2[i]) != -1 === false) {
      return false;
    }
    // Else return true
  } return true;
}


// Example call
mutation(["hello", "hey"]);