quantitivecalc
Version:
A TypeScript library providing advanced quantitative finance functions for risk analysis, performance metrics, and technical indicators. (Currently in development)
21 lines (20 loc) • 830 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = setFirstItemProperty;
/**
* Returns a new array where the first item's specified property is set to the given value.
* The rest of the items remain unchanged.
*
* @template T - The type of items in the list.
* @template K - The key of the property to update.
* @param list - The array of items.
* @param columnName - The property name to update on the first item.
* @param value - The new value to assign to the specified property.
* @returns A new array with the first item's property updated, or an empty array if the input list is empty.
*/
function setFirstItemProperty(list, columnName, value) {
if (list.length === 0) {
return [];
}
return [{ ...list[0], [columnName]: value }, ...list.slice(1)];
}