Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into run-test-on-every-git…
Browse files Browse the repository at this point in the history
…-push
  • Loading branch information
uwaseem committed Oct 20, 2020
2 parents 4e26c93 + 3dfe405 commit 99f6388
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 1,183 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)

# random-dessert-generator
Randomly gets a dessert name from a precompiled list

Expand Down
14 changes: 14 additions & 0 deletions data/adjectives.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
exports.adjectives = [
'bbq',
'berrylicious',
'butterscotch',
'caramel',
'cheesy',
'chocolate',
'salted egg',
'salty',
'smoked',
'strawberry',
'sugar',
'sweet'
]
22 changes: 22 additions & 0 deletions data/desserts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
exports.desserts = [
'ais kacang',
'akok',
'apple crumble',
'brownies',
'buchty',
'cake',
'cekodok',
'cempedak creme',
'cempedak fritters',
'cendol',
'chocolate',
'cupcake',
'eclair',
'frgál',
'kek lapis',
'krapfen',
'kremrole',
'muffin',
'tart',
'větrník'
]
6 changes: 3 additions & 3 deletions helpers/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function getRandomIndex(array) {
return Math.floor(Math.random() * array.length);
function getRandomIndex (array) {
return Math.floor(Math.random() * array.length)
}

exports.getRandomIndex = getRandomIndex;
exports.getRandomIndex = getRandomIndex
25 changes: 12 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
const utils = require('./helpers/utils');

const desserts = ['ais kacang', 'akok', 'apple crumble', 'brownies', 'buchty', 'cake', 'cekodok', 'cempedak creme', 'cempedak fritters', 'cendol', 'chocolate', 'cupcake', 'eclair', 'frgál', 'kek lapis', 'krapfen', 'kremrole', 'muffin', 'tart', 'větrník']
const adjectives = ['bbq', 'berrylicious', 'butterscotch', 'caramel', 'cheesy', 'chocolate', 'salted egg', 'salty', 'smoked', 'strawberry', 'sugar', 'sweet']
const { getRandomIndex } = require('./helpers/utils')
const { adjectives } = require('./data/adjectives')
const { desserts } = require('./data/desserts')

/**
* Generate a dessert.
* @return {string} A random dessert name
*/
function generateDessert() {
const dessertIndex = utils.getRandomIndex(desserts);
return desserts[dessertIndex];
function generateDessert () {
const dessertIndex = getRandomIndex(desserts)
return desserts[dessertIndex]
}

/**
* Generate a dessert with an adjective.
* @return {string} A random dessert name with an adjective
*/
function generateYummyDessert() {
const dessertIndex = utils.getRandomIndex(desserts);
const adjectiveIndex = utils.getRandomIndex(adjectives);
return `${adjectives[adjectiveIndex]} ${desserts[dessertIndex]}`;
function generateYummyDessert () {
const dessertIndex = getRandomIndex(desserts)
const adjectiveIndex = getRandomIndex(adjectives)
return `${adjectives[adjectiveIndex]} ${desserts[dessertIndex]}`
}

exports.generateDessert = generateDessert;
exports.generateYummyDessert = generateYummyDessert;
exports.generateDessert = generateDessert
exports.generateYummyDessert = generateYummyDessert
Loading

0 comments on commit 99f6388

Please sign in to comment.