forked from zuriby/Faker.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactoring so we do not need to use Helpers.randomize() everywhere
- Loading branch information
1 parent
8a6ad8d
commit 0b3cfbe
Showing
4 changed files
with
83 additions
and
50 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
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
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
var definitions = require('./definitions'); | ||
|
||
var random = { | ||
// returns a single random number based on a range | ||
number: function (range) { | ||
var r = Math.floor(Math.random() * range); | ||
console.log(r); | ||
return r; | ||
}, | ||
|
||
// takes an array and returns the array randomly sorted | ||
array_rand: function (array) { | ||
var r = Math.floor(Math.random() * array.length); | ||
return array[r]; | ||
} | ||
}; | ||
|
||
var method_names = [ | ||
'catch_phrase_adjective', | ||
'catch_phrase_descriptor', | ||
'catch_phrase_noun', | ||
'bs_adjective', | ||
'bs_buzz', | ||
'bs_noun' | ||
]; | ||
|
||
for (var i = 0; i < method_names.length; i++) { | ||
var method_name = method_names[i]; | ||
random[method_name] = function () { | ||
return random.array_rand(definitions[method_name]()); | ||
}; | ||
} | ||
|
||
module.exports = random; |
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