@mui/x-charts
Version:
The community edition of MUI X Charts components.
17 lines • 454 B
JavaScript
/**
* Given a map of arrays, appends a value to the array at the given key.
* If no array exists at that key, one is created and the value appended.
* @param map Map of arrays
* @param key Key to append the value at
* @param value Value to append
*/
export function appendAtKey(map, key, value) {
let bucket = map.get(key);
if (!bucket) {
bucket = [value];
map.set(key, bucket);
} else {
bucket.push(value);
}
return bucket;
}