Skip to content

Instantly share code, notes, and snippets.

@deebloo
Last active January 13, 2022 19:32
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 deebloo/713f67a0a2e55d49b1a80c3b3a96280e to your computer and use it in GitHub Desktop.
Save deebloo/713f67a0a2e55d49b1a80c3b3a96280e to your computer and use it in GitHub Desktop.
function* windowed<T>(arr: T[], size: number) {
for (let i = 0; i < arr.length; i++) {
yield arr.slice(i, size + i);
}
}
let thing = windowed([0, 1, 2, 3], 2);
for (let [a, b] of thing) {
console.log(a, b);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment