Files
webstudio/apps/builder/app/shared/array-utils.ts
T
Bogdan Chadkin fc81392df9 fix: transition bugs (#3730)
- fixed default duration
- fixed repeating logic when view, add or delete transitions
- prevent showing transition-behavior property when use transitions UI
2024-07-15 18:28:23 +02:00

22 lines
577 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 < count; index += 1) {
repeatedArray.push(array[index % array.length]);
}
return repeatedArray;
};