export function sum<T>(items: T[], selector: (item: T) => number) { return Array.from(items).reduce((a, x) => a + (selector(x) || 0), 0); } interface IWithValue { value: number; } const data: IWithValue[] = [{value: 1},{value: 2}, {value: 3}, {value: 4}]; console.log(sum(data, (x) => x.value)); // 10
574200cookie-checkTypescript sum