Skip to content

Instantly share code, notes, and snippets.

@deliseev
Created February 28, 2019 15:00
Show Gist options
  • Save deliseev/8f385cfd3405822770cd93035120e879 to your computer and use it in GitHub Desktop.
Save deliseev/8f385cfd3405822770cd93035120e879 to your computer and use it in GitHub Desktop.
Itertool for js
// 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