UNPKG

quantitivecalc

Version:

A TypeScript library providing advanced quantitative finance functions for risk analysis, performance metrics, and technical indicators. (Currently in development)

30 lines (29 loc) 1.08 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = findExtremesInColumn; /** * Finds the items with the minimum and maximum values in a specified column of an array of objects. * * @template T - The type of objects in the list. * @template K - The key of the column to compare, must be a key of T with comparable values. * @param list - The array of objects to search. * @param columnName - The key of the column to find extremes in. * @returns An object containing the items with the minimum and maximum values in the specified column. * If the list is empty, both `min` and `max` will be `undefined`. */ function findExtremesInColumn(list, columnName) { if (list.length === 0) { return { min: undefined, max: undefined }; } let min = list[0]; let max = list[0]; for (const item of list) { if (item[columnName] < min[columnName]) { min = item; } if (item[columnName] > max[columnName]) { max = item; } } return { min, max }; }