Last active
February 7, 2018 01:43
-
-
Save Jacob-Doetsch/29657d068581b6d0f5d1a387d3952359 to your computer and use it in GitHub Desktop.
Chinese restaurant 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
/** | |
* Randomly generates and returns the the name | |
* of a Chinese restaurant, with the given length | |
* of words | |
* | |
* @param {number} len desired name length | |
* in words (2 or 3 supported) | |
* @returns {string|null} the generated name, or | |
* null if the given name length is invalid | |
*/ | |
function generateName (len) { | |
if (len < 2 || len > 3) { | |
return null; | |
} | |
let phrases = { | |
head: ["China", "Sichuan", "Yunnan", "Hot", "Golden", "Red", "Spicy", "Old", "Eastern"], | |
tail: ["Dragon", "Wok", "Lantern", "Taste", "Spice", "Flavor", "Dynasty", "Emperor", "Lotus", "Panda"] | |
}; | |
let n = []; | |
n.push(phrases.head[Math.floor(Math.random(phrases.head.length))]); | |
n.push(phrases.tail[Math.floor(Math.random(phrases.tail.length))]); | |
if (len === 3) { | |
n.unshift(phrases.head[Math.floor(Math.random(phrases.head.length))]); | |
} | |
return n.join(" "); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment