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; +}