aneka
Version:
Some usefull function helper for daily use
18 lines (15 loc) • 488 B
JavaScript
/**
* Filter array's indexes
*
* @param {Array} inputs - Array to filter from
* @param {Object} matcher - Function to match conditions. If returns ```true```, the running index will be added to the result
* @returns {Array} Filtered indexes
*/
function filterIndex (inputs, matcher) {
const indexes = inputs.reduce((accumulator, current, index) => {
if (matcher(current)) accumulator.push(index)
return accumulator
}, [])
return indexes
}
export default filterIndex