From d04f498c99046c7cb07d21e86183b338b9727572 Mon Sep 17 00:00:00 2001 From: Andros Fenollosa Date: Wed, 9 Feb 2022 16:57:17 +0100 Subject: [PATCH] Update fnTools.ts --- src/fnTools.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/fnTools.ts b/src/fnTools.ts index e96349c..a354dea 100644 --- a/src/fnTools.ts +++ b/src/fnTools.ts @@ -155,4 +155,17 @@ export function getRandom(min, max, decimals=0) { const minRandom = Math.ceil(min); const maxRandom = Math.floor(max); return (Math.random() * (maxRandom - minRandom + 1) + minRandom).toFixed(decimals); -} \ No newline at end of file +} + +/** + * 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} list - List of files. + * @return number + */ +function getIndexOfFileList(name: string, list: Array): number { + return list.reduce( + (position, file, index) => (file.name === name ? index : position), + -1 + ); +}