Last active
May 8, 2018 13:36
-
-
Save fernandocanizo/518319c982a79ea277305d4d66afbd21 to your computer and use it in GitHub Desktop.
fantasy animal generator
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
'use strict'; | |
const randomItem = (itemsArray) => itemsArray[Math.floor(Math.random() * itemsArray.length)]; | |
const makeFantasyAnimal = () => { | |
const animales = ['perro', 'gato', 'jirafa']; | |
const verbos = ['escupe', 'caga', 'estornuda']; | |
const elementos = ['fuego', 'hielo', 'moco']; | |
return `${randomItem(animales)} ${randomItem(verbos)} ${randomItem(elementos)}`; | |
}; | |
function * buildAnimalArmy() { | |
while (Math.random() > .1) { | |
yield makeFantasyAnimal(); | |
} | |
} | |
for (const fantasyAnimal of buildAnimalArmy()) { | |
console.log(fantasyAnimal); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment