Skip to content

Instantly share code, notes, and snippets.

@SerhiiLihus
Created December 4, 2015 12:11
Show Gist options
  • Save SerhiiLihus/66811f77f49398c3642f to your computer and use it in GitHub Desktop.
Save SerhiiLihus/66811f77f49398c3642f to your computer and use it in GitHub Desktop.
Check if first word in array contain all letters from second word in array
// Bonfire: Mutations
// Author: @serhiilihus
// Challenge: http://www.freecodecamp.com/challenges/bonfire-mutations?solution=function%20mutation(arr)%20%7B%0A%20%20var%20i%20%3D%200%3B%0A%20%20arr%5B0%5D%20%3D%20arr%5B0%5D.toLowerCase()%3B%0A%20%20while%20(arr%5B0%5D.indexOf(arr%5B1%5D.charAt(i).toLowerCase())%20!%3D%20-1%20%26%26%20i%20%3C%20arr%5B1%5D.length%20)%20i%2B%2B%3B%0A%20%20%0A%20%20return%20(i%20%3D%3D%3D%20arr%5B1%5D.length)%3F%20true%20%3A%20false%3B%0A%7D%0A%0Amutation(%5B%22hello%22%2C%20%22hey%22%5D)%3B%0A
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function mutation(arr) {
var i = 0;
arr[0] = arr[0].toLowerCase();
while (arr[0].indexOf(arr[1].charAt(i).toLowerCase()) != -1 && i < arr[1].length ) i++;
return (i === arr[1].length)? true : false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment