function invertMapKeyValues(map) {
  const inverted = new Map();

  for(let [key, value] of map.entries()) {
    if (inverted.has(value)) {
      inverted.set(value, inverted.get(value).concat(key));
    } else {
      inverted.set(value, [key]);
    }
  }

  return inverted;
}
Invert key and values in a Map.
Similar to _.invert (https://lodash.com/docs/4.17.11#invert)
@param {*} map