-
-
Save anonymous/2dcadc9e508d612dd053 to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/v3rse '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: @v3rse | |
// Challenge: http://www.freecodecamp.com/challenges/bonfire-mutations?solution=function%20mutation(arr)%20%7B%0A%20%20var%20state%3B%0A%20%20var%20string1%20%3D%20arr%5B0%5D.toLowerCase()%3B%0A%20%20var%20string2%20%3D%20arr%5B1%5D.toLowerCase()%3B%0A%20%20for(var%20i%20%3D%200%3B%20i%20%3C%20arr%5B1%5D.length%3B%20i%2B%2B)%7B%0A%20%20%20%20var%20value%20%3D%20string1.indexOf(string2.charAt(i))%3B%0A%20%20%20%20if(value%20%3D%3D%3D%20-1)%7B%0A%20%20%20%20%20%20return%20false%3B%0A%20%20%20%20%7Delse%7B%0A%20%20%20%20%20%20state%20%3D%20true%3B%0A%20%20%20%20%7D%0A%20%20%7D%0A%20%20%0A%20%20return%20state%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 state; | |
var string1 = arr[0].toLowerCase(); | |
var string2 = arr[1].toLowerCase(); | |
for(var i = 0; i < arr[1].length; i++){ | |
var value = string1.indexOf(string2.charAt(i)); | |
if(value === -1){ | |
return false; | |
}else{ | |
state = true; | |
} | |
} | |
return state; | |
} | |
mutation(["hello", "hey"]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment