Skip to content

Commit

Permalink
fix-enumerate-typing
Browse files Browse the repository at this point in the history
  • Loading branch information
uriva committed Dec 22, 2023
1 parent 51d8a3a commit d439740
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ export const includedIn = <T>(array: T[]) => (x: T) => array.includes(x);
export const take = <T>(n: number) => (xs: T[]) => xs.slice(0, n);
export const drop = <T>(n: number) => (xs: T[]) => xs.slice(n);

export const enumerate = <T>(xs: T[]) => xs.map((x, i) => [i, x]);
export const enumerate = <T>(xs: T[]): [number, T][] =>
xs.map((x, i) => [i, x]);

export const slidingWindow = <T>(l: number) => (xs: T[]) =>
xs.flatMap((_, i) => (i <= xs.length - l ? [xs.slice(i, i + l)] : []));

0 comments on commit d439740

Please sign in to comment.