Skip to content

Commit

Permalink
add utility fn
Browse files Browse the repository at this point in the history
  • Loading branch information
ibelar committed Jun 5, 2024
1 parent 6441e99 commit 55b1194
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/components/utils/composable/utils.js
Original file line number Diff line number Diff line change
@@ -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 }

0 comments on commit 55b1194

Please sign in to comment.