Last active
April 20, 2018 16:06
-
-
Save a-eid/77e23f51609bcba03c10ac37f016302c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
@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