UNPKG

528 BJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.arrayShuffle = arrayShuffle;
7
8// Copyright 2017-2022 @polkadot/util authors & contributors
9// SPDX-License-Identifier: Apache-2.0
10function arrayShuffle(input) {
11 const result = input.slice();
12 let curr = result.length;
13
14 if (curr === 1) {
15 return result;
16 }
17
18 while (curr !== 0) {
19 const rand = Math.floor(Math.random() * curr);
20 curr--;
21 [result[curr], result[rand]] = [result[rand], result[curr]];
22 }
23
24 return result;
25}
\No newline at end of file