logos-delivery-js/src/lib/push_or_init_map.ts

14 lines
250 B
TypeScript
Raw Normal View History

export function pushOrInitMapSet<K, V>(
map: Map<K, Set<V>>,
key: K,
newValue: V
): void {
let arr = map.get(key);
if (typeof arr === "undefined") {
map.set(key, new Set());
arr = map.get(key) as Set<V>;
}
arr.add(newValue);
}