From 6a2ee0b2df7f5ff0a6b868ef84d656375e5d2895 Mon Sep 17 00:00:00 2001 From: Andros Fenollosa Date: Thu, 10 Feb 2022 09:30:34 +0100 Subject: [PATCH] Update fnTools.ts --- src/fnTools.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/fnTools.ts b/src/fnTools.ts index 784effe..46c9e11 100644 --- a/src/fnTools.ts +++ b/src/fnTools.ts @@ -191,3 +191,17 @@ export function arrayFilesToFileList(filesList) { return dataTransfer; }, new DataTransfer()).files; } + +/** + * Returns a copy of the Array by swapping 2 indices. + * @param {number} firstIndex + * @param {number} secondIndex + * @param {Array} list + */ +export function arraySwapIndex(firstIndex: number, secondIndex: number, list: Array): Array { + const tempList = list.slice(); + const tmpFirstPos = tempList[firstIndex]; + tempList[firstIndex] = tempList[secondIndex]; + tempList[secondIndex] = tmpFirstPos; + return tempList; +}