Update fnTools.ts

This commit is contained in:
Andros Fenollosa 2022-02-09 16:57:17 +01:00 committed by GitHub
parent cdd6a48b47
commit d04f498c99
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -156,3 +156,16 @@ export function getRandom(min, max, decimals=0) {
const maxRandom = Math.floor(max); const maxRandom = Math.floor(max);
return (Math.random() * (maxRandom - minRandom + 1) + minRandom).toFixed(decimals); return (Math.random() * (maxRandom - minRandom + 1) + minRandom).toFixed(decimals);
} }
/**
* Returns the index of an Array of Files from its name. If there are multiple files with the same name, the last one will be returned.
* @param {string} name - Name file.
* @param {Array<File>} list - List of files.
* @return number
*/
function getIndexOfFileList(name: string, list: Array<File>): number {
return list.reduce(
(position, file, index) => (file.name === name ? index : position),
-1
);
}