From 25d6725d8f38974502ba76b4ab44554cbfd7fdc7 Mon Sep 17 00:00:00 2001 From: nimbleghost <132819643+nimbleghost@users.noreply.github.com> Date: Wed, 24 May 2023 17:49:04 +0200 Subject: [PATCH] Use es6 destructuring swap for shuffling --- web/src/app/utils.js | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/web/src/app/utils.js b/web/src/app/utils.js index 0af10330..481d6031 100644 --- a/web/src/app/utils.js +++ b/web/src/app/utils.js @@ -139,17 +139,14 @@ export const maybeAppendActionErrors = (message, notification) => { }; export const shuffle = (arr) => { - let j; - let x; - for (let index = arr.length - 1; index > 0; index -= 1) { - j = Math.floor(Math.random() * (index + 1)); - x = arr[index]; - // eslint-disable-next-line no-param-reassign - arr[index] = arr[j]; - // eslint-disable-next-line no-param-reassign - arr[j] = x; + const returnArr = [...arr]; + + for (let index = returnArr.length - 1; index > 0; index -= 1) { + const j = Math.floor(Math.random() * (index + 1)); + [returnArr[index], returnArr[j]] = [returnArr[j], returnArr[index]]; } - return arr; + + return returnArr; }; export const splitNoEmpty = (s, delimiter) =>