mirror of
https://github.com/webstudio-is/webstudio.git
synced 2026-10-29 08:07:48 +09:00
22 lines
601 B
TypeScript
22 lines
601 B
TypeScript
type Predicate<Item> = (value: Item) => boolean;
|
|
|
|
export const removeByMutable = <Item>(
|
|
array: Item[],
|
|
predicate: Predicate<Item>
|
|
) => {
|
|
// reversed order to splice without breaking index
|
|
for (let index = array.length - 1; index >= 0; index -= 1) {
|
|
if (predicate(array[index])) {
|
|
array.splice(index, 1);
|
|
}
|
|
}
|
|
};
|
|
|
|
export const repeatUntil = <Item>(array: Item[], count: number) => {
|
|
const repeatedArray: Item[] = [];
|
|
for (let index = 0; index < Math.max(count, array.length); index += 1) {
|
|
repeatedArray.push(array[index % array.length]);
|
|
}
|
|
return repeatedArray;
|
|
};
|