1
0
Fork 0
mirror of https://github.com/pawelmalak/flame.git synced 2025-07-19 19:49:37 +02:00
flame/client/src/utility/array.ts

18 lines
363 B
TypeScript
Raw Normal View History

2022-11-30 20:46:28 +00:00
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),
];