Last active
September 9, 2018 23:48
-
-
Save benchristel/c47faab3b269d8dc45c78221e392553f to your computer and use it in GitHub Desktop.
Wizard name generator in Verse
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
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