mirror of
https://github.com/pawelmalak/flame.git
synced 2025-07-19 19:49:37 +02:00
18 lines
363 B
TypeScript
18 lines
363 B
TypeScript
|
export const arrayPartition = <T>(
|
||
|
arr: T[],
|
||
|
isValid: (e: T) => boolean
|
||
|
): T[][] => {
|
||
|
let pass: T[] = [];
|
||
|
let fail: T[] = [];
|
||
|
|
||
|
arr.forEach((e) => (isValid(e) ? pass : fail).push(e));
|
||
|
|
||
|
return [pass, fail];
|
||
|
};
|
||
|
|
||
|
export const insertAt = <T>(arr: T[], index: number, element: T): T[] => [
|
||
|
...arr.slice(0, index),
|
||
|
element,
|
||
|
...arr.slice(index + 1),
|
||
|
];
|