Skip to content

Instantly share code, notes, and snippets.

@deebloo
Last active January 13, 2022 19:32
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
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