simonpweller / quotes-api

An easy-to-use API for fetching programming quotes.
0 stars 3 forks source link

Need randomization function #2

Closed simonpweller closed 4 years ago

simonpweller commented 4 years ago

As we add more quotes we need a function to select a random item from an array. Only one precondition - let's not pull in any new libraries just for this.

simonpweller commented 4 years ago

I added a stub for this here: https://github.com/simonpweller/quotes-api/blob/master/src/utils.js and a couple of automated tests - once the function is implemented, the tests should pass

nibble0101 commented 4 years ago

As we add more quotes we need a function to select a random item from an array. Only one precondition - let's not pull in any new libraries just for this.

Don't you think it is important to name the function getRandomQuote instead of getRandomElement? I think this is necessary because the latter is more generic while the former is more specific if an array of quotes is passed to it and a random quote is returned.

simonpweller commented 4 years ago

Hm, it depends I guess. I called it getRandomElement since I figured it could be written so that it would work for any array you pass in. If it was called getRandomQuote, I would expect that it returns a quote without me having to pass anything in.

Maybe the function in utils.js could keep the name getRandomElement and then quotes.js exposes a function getRandomQuote that uses getRandomElement under the hood?