Skip to content

Instantly share code, notes, and snippets.

@a-eid
Last active April 20, 2018 16:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save a-eid/77e23f51609bcba03c10ac37f016302c to your computer and use it in GitHub Desktop.
Save a-eid/77e23f51609bcba03c10ac37f016302c to your computer and use it in GitHub Desktop.
/*
@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