Update fnTools.ts

This commit is contained in:
Andros Fenollosa 2022-02-10 09:30:34 +01:00 committed by GitHub
parent a330ffa653
commit 6a2ee0b2df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -191,3 +191,17 @@ export function arrayFilesToFileList(filesList) {
return dataTransfer; return dataTransfer;
}, new DataTransfer()).files; }, new DataTransfer()).files;
} }
/**
* Returns a copy of the Array by swapping 2 indices.
* @param {number} firstIndex
* @param {number} secondIndex
* @param {Array<any>} list
*/
export function arraySwapIndex(firstIndex: number, secondIndex: number, list: Array<any>): Array<any> {
const tempList = list.slice();
const tmpFirstPos = tempList[firstIndex];
tempList[firstIndex] = tempList[secondIndex];
tempList[secondIndex] = tmpFirstPos;
return tempList;
}