-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(random): Add ability to get an array of random Harry Potter names
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
Gonzalo Manrique
committed
Jul 11, 2017
1 parent
c6dadb7
commit 52839f3
Showing
2 changed files
with
23 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters