Skip to content

Instantly share code, notes, and snippets.

@scarlac
Created February 9, 2018 21:53
Show Gist options
  • Save scarlac/c16897f25709188fc29b59e740a30375 to your computer and use it in GitHub Desktop.
Save scarlac/c16897f25709188fc29b59e740a30375 to your computer and use it in GitHub Desktop.
"It seems like you could randomly generate Danish names using the formula of five letters, double consenant and an e at the end." - Challenge accepted.
const all = 'abcdefghijklmnopqrstuvwxyzæøå';
const consonants = 'bcdfghjklmnpqrstvwxz';
function randomLetter() {
return all[parseInt(Math.random() * all.length)];
}
function randomConsonant() {
return consonants[parseInt(Math.random() * consonants.length)];
}
for(let i = 0; i < 10; i++) {
let first = randomLetter();
let second = randomLetter();
let third = randomLetter();
let fourth = randomLetter();
const fifth = 'e';
const secondOrThird = Math.random() > .5 ? 'second' : 'third';
while (second == first) {
second = randomLetter();
}
if (secondOrThird == 'second') {
second = randomConsonant();
third = second;
} else {
third = randomConsonant();
fourth = third;
}
while (first == second) {
first = randomLetter();
}
console.log(`${first}${second}${third}${fourth}${fifth}`);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment