Typescript create map

Date: 2024-07-01
export function createMap<TSource, TKey, TValue>(items: Iterable<TSource>, keySelector: (x: TSource) => TKey, valueSelector: (x: TSource) => TValue): Map<TKey, TValue> {
    const m = new Map<TKey, TValue>();
    for (const item of items) {
        const key = keySelector(item);
        const value = valueSelector(item);
        m.set(key, value);
    }
    return m;
}
86700cookie-checkTypescript create map