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) • 878 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = applyFunction;
/**
* Applies a provided function to each array value in a dictionary and returns a new dictionary
* with the same keys and the results of the function as values.
*
* @template T - The type of elements in the input arrays.
* @template R - The type of the result returned by the function.
* @param dict - A dictionary where each value is an array of type T.
* @param func - A function that takes an array of type T and returns a value of type R.
* @returns A new dictionary with the same keys as `dict`, where each value is the result of applying `func` to the corresponding array.
*/
function applyFunction(dict, func) {
const result = {};
for (const [key, list] of Object.entries(dict)) {
result[key] = func(list);
}
return result;
}