diff --git a/src/index.js b/src/index.js index 27e18cc..8a4cfab 100644 --- a/src/index.js +++ b/src/index.js @@ -1,7 +1,20 @@ var uniqueRandomArray = require('unique-random-array'); var dikkenekQuotes = require('./dikkenek-quotes.json'); +var getRandomItem = uniqueRandomArray(dikkenekQuotes); module.exports = { all: dikkenekQuotes, - random: uniqueRandomArray(dikkenekQuotes) + random: random }; + +function random(number){ + if (number === undefined) { + return getRandomItem(); + } else { + var randomItem = []; + for (var i = 0; i < number; i++) { + randomItem.push(getRandomItem()); + } + return randomItem; + } +} diff --git a/src/index.test.js b/src/index.test.js index ff70391..b0e8264 100644 --- a/src/index.test.js +++ b/src/index.test.js @@ -16,6 +16,7 @@ describe('dikkenek-quotes', function(){ it('it should contain `C’est excessivement énervant !`', function(){ expect(dikkenek.all).to.include('C’est excessivement énervant !'); }); + }); describe('random', function(){ @@ -23,5 +24,13 @@ describe('dikkenek-quotes', function(){ var randomItem = dikkenek.random(); expect(dikkenek.all).to.include(randomItem); }); + + it('should return an array of random items if passed a number', function(){ + var randomItem = dikkenek.random(3); + expect(randomItem).to.have.length(3); + randomItem.forEach(function(item){ + expect(dikkenek.all).to.include(item); + }) + }); }); });