diff --git a/src/components/utils/composable/utils.js b/src/components/utils/composable/utils.js new file mode 100644 index 0000000..db9d831 --- /dev/null +++ b/src/components/utils/composable/utils.js @@ -0,0 +1,17 @@ + + +/** + * Return an array index matching the testing function (fn) + * If no index is found, then return a default one. + * + */ +const useFindIndexDefault = (ar, fn, defaultIdx = 0) => { + let idx = ar.findIndex(fn); + if (idx === -1) { + idx = defaultIdx; + } + + return idx; +} + +export { useFindIndexDefault } \ No newline at end of file