2023-12-03 12:17:08 +00:00
|
|
|
export const matchAllAndThen = (input: string, pattern: RegExp, callback: (value: string, index: number) => void) => {
|
2023-12-17 13:50:20 +00:00
|
|
|
[...input.matchAll(pattern)].map(match => {
|
|
|
|
if (match && match.index !== undefined) {
|
|
|
|
callback(match[0], match.index);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export const window = <T>(input: T[], size: number): T[][] => {
|
|
|
|
return input.reduce((windows, value, index) => {
|
|
|
|
if (index === input.length - size + 1) return windows;
|
|
|
|
return [...windows, input.slice(index, index + size)];
|
|
|
|
}, [] as T[][]);
|
2023-12-03 12:17:08 +00:00
|
|
|
}
|