Skip to content

Instantly share code, notes, and snippets.

@rostegg
Created September 2, 2021 12:07
Show Gist options
  • Save rostegg/bc9abd989c3f6753cd835e238c32513e to your computer and use it in GitHub Desktop.
Save rostegg/bc9abd989c3f6753cd835e238c32513e to your computer and use it in GitHub Desktop.
Group elemnts of array, skiping last N elements in group
function groupSkip(arr, shift, skip = 1) {
const res = []
let limit = 0
while (limit+shift <= arr.length) {
res.push(arr.slice(limit, shift + limit - skip))
limit += shift
}
return res
}
const res = groupSkip(array, 4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment