Created
December 10, 2015 06:29
-
-
Save joePichardo/053655aaa9f9bb9fad83 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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Bonfire: Mutations | |
// Author: @joepichardo | |
// Challenge: http://www.freecodecamp.com/challenges/bonfire-mutations | |
// Learn to Code at Free Code Camp (www.freecodecamp.com) | |
function mutation(arr) { | |
/* | |
compareChars is made into an array of lowerCase letters | |
compareToString is the string to compare the letters with and it is lowercased | |
we make containsChars true at first, until function tells us otherwise | |
*/ | |
var compareChars = arr[1].toString().toLowerCase().split(""); | |
var compareToString = arr[0].toString().toLowerCase(); | |
var containsChars = true; | |
/* | |
we go through the letters we need to compare, | |
hence the arr[1] string length comparison | |
if letter is not in the string we are comparing | |
it to -1 is returned, which then returns a false value | |
*/ | |
for(var i = 0; i < arr[1].toString().length; i++){ | |
if(compareToString.indexOf(compareChars[i]) == -1){ | |
containsChars = false; | |
} | |
} | |
return containsChars ; | |
} | |
mutation(["hello", "hey"]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment