-
Notifications
You must be signed in to change notification settings - Fork 39
/
util.js
40 lines (25 loc) · 933 Bytes
/
util.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
module.exports = {
titleCase(str) {
var splitStr = str.toLowerCase().split(' ');
for (var i = 0; i < splitStr.length; i++) {
splitStr[i] = splitStr[i].charAt(0).toUpperCase() + splitStr[i].substring(1);
}
return splitStr.join(' ');
},
getRandomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
var random = Math.floor(Math.random() * (max - min + 1)) + min;
console.log(`[${min},${max}] -> ${random}`);
return random;
},
shuffle(array) {
let currentIndex = array.length, randomIndex;
while (currentIndex != 0) {
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex--;
[array[currentIndex], array[randomIndex]] = [array[randomIndex], array[currentIndex]];
}
return array;
}
}