UNPKG

everyutil

Version:

A comprehensive library of lightweight, reusable utility functions for JavaScript and TypeScript, designed to streamline common programming tasks such as string manipulation, array processing, date handling, and more.

19 lines (18 loc) 524 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.arrayFrequencyMap = void 0; /** * Returns a map of element frequencies in the array. * @author @dailker * @template T * @param {T[]} array - Input array. * @returns {Map<T, number>} Frequency map. */ function arrayFrequencyMap(array) { const map = new Map(); for (const item of array) { map.set(item, (map.get(item) || 0) + 1); } return map; } exports.arrayFrequencyMap = arrayFrequencyMap;