UNPKG

417 BJavaScriptView Raw
1// Copyright 2017-2022 @polkadot/util authors & contributors
2// SPDX-License-Identifier: Apache-2.0
3export function arrayShuffle(input) {
4 const result = input.slice();
5 let curr = result.length;
6
7 if (curr === 1) {
8 return result;
9 }
10
11 while (curr !== 0) {
12 const rand = Math.floor(Math.random() * curr);
13 curr--;
14 [result[curr], result[rand]] = [result[rand], result[curr]];
15 }
16
17 return result;
18}
\No newline at end of file