You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
480 B
TypeScript

export const setIdx = <T>(arr: T[], index: number, newValue: T): T[] => {
const newArr = [...arr];
newArr[index] = newValue;
return newArr;
};
export const push = <T>(arr: T[], newValue: T) => [...arr, newValue];
export const deleteIdx = <T>(arr: T[], index: number): T[] => {
const newArr = [...arr];
newArr.splice(index, 1);
return newArr;
};
export const setProp = <T, K extends keyof T>(
obj: T,
key: K,
newValue: T[K],
): T => ({
...obj,
[key]: newValue,
});