Skip to content

Instantly share code, notes, and snippets.

@dan-lee
Created August 28, 2022 21:39
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 dan-lee/a0d5ad72302b168ea836ba787d7f9eb1 to your computer and use it in GitHub Desktop.
Save dan-lee/a0d5ad72302b168ea836ba787d7f9eb1 to your computer and use it in GitHub Desktop.
Rust-like `windows` for arrays
const windows = <T>(array: T[], slice = 2): T[][] =>
Array.from({ length: array.length - slice }).reduce<T[][]>((result, _, i) => {
return [...result, array.slice(i, slice + i)]
}, [])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment