Last active
May 2, 2017 12:41
-
-
Save mozkoq/676be150ab68d774a5ad4e799e4c8b32 to your computer and use it in GitHub Desktop.
russian name generator
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
const CONSONANT = "бвгджзклмнпрстфхцчшщ" | |
const VOWEL = "еёаиэюяоу" | |
const isFirst = i => i == 0 | |
const isEven = n => (n % 2) == 0 | |
const rand = n => | |
Math.floor(Math.random() * n) | |
const randChar = string => | |
string.charAt(rand(string.length)) | |
const genChar = (el, i) => | |
isEven(i) | |
? randChar(CONSONANT) | |
: randChar(VOWEL) | |
const joinName = (state, cur, i) => | |
state + ( | |
isFirst(i) | |
? cur.toUpperCase() | |
: cur | |
) | |
const genName = (length = 5) => | |
Array.from({ length }, genChar) | |
.reduce(joinName, []) | |
console.log(genName()) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment