Created
June 22, 2018 10:10
-
-
Save bozheville/57c49935334c948fb33bc389e8e15fac to your computer and use it in GitHub Desktop.
random name 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
const randomContactName = () => { | |
const getCharFrom = set => set.charAt( | |
Math.round( Math.random() * ( set.length - 1 ) ) | |
); | |
const getVowel = () => getCharFrom( 'aeiouy' ); | |
const getConsonant = () => getCharFrom( 'bcdfghjklmnpqrstvwxz' ); | |
let name = getConsonant() + getVowel() + getConsonant(); | |
if ( Math.random() >= 0.5 ) { | |
name += name[ name.length - 1 ]; | |
} | |
name += getVowel(); | |
if ( Math.random() >= 0.5 ) { | |
name += getConsonant() + getVowel(); | |
} | |
return name.charAt( 0 ).toUpperCase() + name.slice( 1 ); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Generated data example: