Created
December 11, 2015 05:36
-
-
Save anonymous/fafb0623b664a095d349 to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/goteamtim 's solution for Bonfire: Mutations
This file contains hidden or 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: @goteamtim | |
| // Challenge: http://www.freecodecamp.com/challenges/bonfire-mutations | |
| // Learn to Code at Free Code Camp (www.freecodecamp.com) | |
| function mutation(arr) { | |
| var wordToSearchIn = arr.shift(); | |
| var seedWord = arr[0]; | |
| //Loop through each letter of first word | |
| for(var i = 0; i < seedWord.length; i++){ | |
| var found = false; | |
| //Loop through each letter of second word and search for the letter in the first | |
| for(var j = 0; j < wordToSearchIn.length; j++){ | |
| //Will loop through one letter of first word per iteration | |
| if(seedWord.charAt(i).toLowerCase() === wordToSearchIn.charAt(j).toLowerCase()){ | |
| found = true; | |
| } | |
| } | |
| if(!found){ | |
| return found; | |
| } | |
| } | |
| return found; | |
| } | |
| mutation(["hello", "helloO"]); | |
| mutation(["hello", "helloO"]); | |
| mutation(["hello", "hey"]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment