Skip to content

Commit

Permalink
feat(random): Add ability to get an array of dikkenek quotes
Browse files Browse the repository at this point in the history
If you pass a number to the random function, you will receive an array with that number of random

items

closes #2
  • Loading branch information
popovkov57 committed Nov 3, 2016
1 parent 963d0ed commit f9df352
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -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;
}
}
9 changes: 9 additions & 0 deletions src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,21 @@ 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(){
it('should return a random item from dikkenk.all', 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);
})
});
});
});

0 comments on commit f9df352

Please sign in to comment.