Skip to content

Instantly share code, notes, and snippets.

@benchristel
Last active September 9, 2018 23:48
Show Gist options
  • Save benchristel/c47faab3b269d8dc45c78221e392553f to your computer and use it in GitHub Desktop.
Save benchristel/c47faab3b269d8dc45c78221e392553f to your computer and use it in GitHub Desktop.
Wizard name generator in Verse
define({
*run() {
yield log('Press any key to generate a name.')
yield function* loop() {
yield waitForChar()
yield log(generateName())
yield retry(loop())
}
},
generateName() {
var v = Bag('aeio')
var c = Bag('rtysdfgklzxvbnm')
return c.draw()
+ v.draw()
+ c.draw()
+ c.draw()
+ v.draw()
+ c.draw()
},
Bag(letters) {
var contents = letters.split('')
return {
draw: draw
}
function draw() {
var index = randomInt(contents.length)
return remove(contents, index)
}
},
randomInt(cap) {
return Math.floor(Math.random() * cap)
},
remove(list, index) {
return list.splice(index, 1)[0]
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment