Closed simonpweller closed 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
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 ofgetRandomElement
? 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.
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?
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.