mirror of
https://github.com/binwiederhier/ntfy.git
synced 2024-11-23 19:59:26 +01:00
Use es6 destructuring swap for shuffling
This commit is contained in:
parent
1291c3afe9
commit
25d6725d8f
1 changed files with 7 additions and 10 deletions
|
@ -139,17 +139,14 @@ export const maybeAppendActionErrors = (message, notification) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const shuffle = (arr) => {
|
export const shuffle = (arr) => {
|
||||||
let j;
|
const returnArr = [...arr];
|
||||||
let x;
|
|
||||||
for (let index = arr.length - 1; index > 0; index -= 1) {
|
for (let index = returnArr.length - 1; index > 0; index -= 1) {
|
||||||
j = Math.floor(Math.random() * (index + 1));
|
const j = Math.floor(Math.random() * (index + 1));
|
||||||
x = arr[index];
|
[returnArr[index], returnArr[j]] = [returnArr[j], returnArr[index]];
|
||||||
// eslint-disable-next-line no-param-reassign
|
|
||||||
arr[index] = arr[j];
|
|
||||||
// eslint-disable-next-line no-param-reassign
|
|
||||||
arr[j] = x;
|
|
||||||
}
|
}
|
||||||
return arr;
|
|
||||||
|
return returnArr;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const splitNoEmpty = (s, delimiter) =>
|
export const splitNoEmpty = (s, delimiter) =>
|
||||||
|
|
Loading…
Reference in a new issue