Skip to content

Instantly share code, notes, and snippets.

@a-eid a-eid/indexes.js
Last active Apr 20, 2018

Embed
What would you like to do?
/*
@arr: array of 0s and 1s
@returns: an array of indexes
*/
const findIndexes = arr => {
return arr.reduce((m, e, i) => {
e && m.push(i)
return m
}, [])
}
/*
@arr: array of 0s and 1s
@returns: an index of the number 1 or undefined
*/
const findIndex = arr => {
return arr.findIndex(x => x == 1)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.