Skip to content

Instantly share code, notes, and snippets.

@mozkoq
Last active May 2, 2017 12:41
Show Gist options
  • Save mozkoq/676be150ab68d774a5ad4e799e4c8b32 to your computer and use it in GitHub Desktop.
Save mozkoq/676be150ab68d774a5ad4e799e4c8b32 to your computer and use it in GitHub Desktop.
russian name generator
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