remove util.js, common/Util.js
This commit is contained in:
parent
d592cef494
commit
3dc9edeee6
4 changed files with 9 additions and 13 deletions
28
common/Util.js
Normal file
28
common/Util.js
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
// get a unique id
|
||||
export const uniqId = () => Date.now().toString(36) + Math.random().toString(36).substring(2)
|
||||
|
||||
// get a random int between min and max (inclusive)
|
||||
export const randomInt = (min, max) => Math.floor(Math.random() * (max - min + 1)) + min
|
||||
|
||||
// get one random item from the given array
|
||||
export const choice = (array) => array[randomInt(0, array.length - 1)]
|
||||
|
||||
// return a shuffled (shallow) copy of the given array
|
||||
export const shuffle = (array) => {
|
||||
let arr = array.slice()
|
||||
for (let i = 0; i <= arr.length - 2; i++)
|
||||
{
|
||||
const j = randomInt(i, arr.length -1);
|
||||
const tmp = arr[i];
|
||||
arr[i] = arr[j];
|
||||
arr[j] = tmp;
|
||||
}
|
||||
return arr
|
||||
}
|
||||
|
||||
export default {
|
||||
uniqId,
|
||||
randomInt,
|
||||
choice,
|
||||
shuffle,
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue