mirror of
https://github.com/pezkuwichain/pezkuwi-common.git
synced 2026-04-22 19:38:02 +00:00
chore: update to version 14.0.11 and align website URLs
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* @name arrayShuffle
|
||||
* @description Shuffles the input array (unlike sort, this is not done in-place)
|
||||
*/
|
||||
export function arrayShuffle(input) {
|
||||
const result = input.slice();
|
||||
let curr = result.length;
|
||||
// noop for the single entry
|
||||
if (curr === 1) {
|
||||
return result;
|
||||
}
|
||||
while (curr !== 0) {
|
||||
// ~~ is more performant than Math.floor
|
||||
const rand = ~~(Math.random() * curr);
|
||||
curr--;
|
||||
[result[curr], result[rand]] = [result[rand], result[curr]];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
Reference in New Issue
Block a user