diff --git a/src/index.js b/src/index.js index d982e90..0329214 100644 --- a/src/index.js +++ b/src/index.js @@ -1,8 +1,21 @@ const uniqueRandomArray = require('unique-random-array'), -harryPotterNames = require('./harry-potter-names.json'); +harryPotterNames = require('./harry-potter-names.json'), +getRandomItem = uniqueRandomArray(harryPotterNames); module.exports = { all: harryPotterNames, - random: uniqueRandomArray(harryPotterNames) + random: random }; + +function random (number) { + if(number === undefined) { + return getRandomItem(); + } else { + let randomItems = []; + for (var i = 0; i < number; i++) { + randomItems.push(getRandomItem()); + } + return randomItems; + } +} diff --git a/src/index.test.js b/src/index.test.js index 225fff2..94353d1 100644 --- a/src/index.test.js +++ b/src/index.test.js @@ -27,5 +27,13 @@ describe('Harry Potter names', function() { expect(harryPotterNames.all).to.include(randomItem); }); + + it('should return a random array of random items if passed a number', function() { + let randomItems = harryPotterNames.random(3); + expect(randomItems).to.have.lengthOf(3); + randomItems.forEach(item => { + expect(harryPotterNames.all).to.include(item); + }); + }); }); });