forked from Geertvdc/faker.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.js
48 lines (41 loc) · 1.22 KB
/
helper.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
(function (Helper) {
// returns a single random number based on a range
Helper.randomNumber = function(range) {
r = Math.floor(Math.random()*range);
return r;
};
// takes an array and returns the array randomly sorted
Helper.randomize = function(array) {
r = Math.floor(Math.random()*array.length);
return array[r];
};
// parses string for a symbol and replace it with a random number from 1-10
Helper.replaceSymbolWithNumber = function(string, symbol){
// default symbol is '#'
if(typeof symbol == 'undefined'){
var symbol = '#';
}
var str = '';
for(var i = 0; i < string.length; i++){
if(string[i] == symbol){
str += Math.floor(Math.random()*10);
}
else{
str += string[i];
}
}
return str;
};
// takes an array and returns it randomized
Helper.shuffle = function(o){
for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
return o;
};
})(
// exports will be set in any commonjs platform; use it if it's available
typeof exports !== "undefined" ?
exports :
// otherwise construct a name space. outside the anonymous function,
// "this" will always be "window" in a browser, even in strict mode.
this.window = {}
);