* Add two views to resource store * Add the endpoints (#4) * add handleAmountChange * add template changes * add components to resourceAccounts * refactor the storeview layout a bit * clean up some stuff, change grand total
13 lines
551 B
TypeScript
13 lines
551 B
TypeScript
export function getObjectFromArray<T>(array: T[], key: keyof T, value: any): T | undefined {
|
|
return array.find(obj => obj[key] === value);
|
|
}
|
|
|
|
export function pushElementToArray<T>(array: T[], element: T): T[] {
|
|
const newArray = [...array]; // create a new array
|
|
newArray.push(element); // add the new element to the array
|
|
return newArray; // return the new array
|
|
}
|
|
|
|
export function sumValues<T extends Record<K, number>, K extends keyof T>(array: T[], key: K): number {
|
|
return array.reduce((acc, obj) => acc + obj[key], 0);
|
|
} |