Created
April 22, 2015 23:14
-
-
Save jason-s13r/d75343d1a8f7761212f6 to your computer and use it in GitHub Desktop.
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
function hangman(word) { | |
var reference = word.replace(/[a-zA-Z]/g,'-'); | |
function reveal(letter) { | |
reference = reference.split('').map(function(v, i){ | |
return word[i] === letter ? letter : v; | |
}).join(''); | |
return reference; | |
}; | |
return { | |
reveal: reveal | |
}; | |
} | |
var game = hangman('carrot'); | |
console.log(game.reveal('r')); | |
console.log(game.reveal('a')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment