Created
February 28, 2019 15:00
-
-
Save deliseev/8f385cfd3405822770cd93035120e879 to your computer and use it in GitHub Desktop.
Itertool for js
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
// drop leading zeroes from array | |
// TODO: make as polyfill | |
// e.g. https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/Array/filter#Polyfill | |
const dropWhile = arr => arr.reduce( | |
(state, v) => (v === 0 && state.drop | |
? ({ arr: [...state.arr], drop: true }) | |
: ({ arr: [...state.arr, v], drop: false })), { arr: [], drop: true }, | |
).arr; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment