Forked from anonymous/bonfire-mutations?solution=function%20mutation(arr)%20%7B%0A%20%20var%20indexLocation%20%3D%200%3B%0A%20%20var%20targetArray%20%3D%20arr%5B0%5D.toLowerCase().split(%22%22)%3B%0A%20%20var%20goalArray%20%3D%20arr%5B1%5D.toLowerCase().split(%22%22)%3B%0
Created
November 17, 2015 08:05
-
-
Save ElliotFriend/dd5131d16999e73af43c to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/elliotfriend 's solution for Bonfire: Mutations
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: @elliotfriend | |
// Challenge: http://www.freecodecamp.com/challenges/bonfire-mutations?solution=function%20mutation(arr)%20%7B%0A%20%20var%20indexLocation%20%3D%200%3B%0A%20%20var%20targetArray%20%3D%20arr%5B0%5D.toLowerCase().split(%22%22)%3B%0A%20%20var%20goalArray%20%3D%20arr%5B1%5D.toLowerCase().split(%22%22)%3B%0A%20%20while%20(goalArray.length%20%3E%200)%20%7B%0A%20%20%20%20indexLocation%20%3D%20targetArray.indexOf(goalArray%5B0%5D)%3B%0A%20%20%20%20if%20(indexLocation%20!%3D%3D%20-1)%20%7B%0A%20%20%20%20%20%20goalArray.shift()%3B%0A%20%20%20%20%7D%20else%20%7B%0A%20%20%20%20%20%20return%20false%3B%0A%20%20%20%20%7D%0A%20%20%7D%0A%20%20return%20true%3B%0A%7D%0A%0Amutation(%5B%22hello%22%2C%20%22mhey%22%5D)%3B%0A | |
// Learn to Code at Free Code Camp (www.freecodecamp.com) | |
function mutation(arr) { | |
var indexLocation = 0; | |
var targetArray = arr[0].toLowerCase().split(""); | |
var goalArray = arr[1].toLowerCase().split(""); | |
while (goalArray.length > 0) { | |
indexLocation = targetArray.indexOf(goalArray[0]); | |
if (indexLocation !== -1) { | |
goalArray.shift(); | |
} else { | |
return false; | |
} | |
} | |
return true; | |
} | |
mutation(["hello", "mhey"]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment