"use strict"; // Inverts an object of arrays, eg. {a: [x, y], b: [x, z]} becomes {x: [a, b], y: [a], z: [b]} // TODO: See if this can be replaced with an off-the-shelf module with equivalent semantics, something transpose-y maybe? module.exports = function invertMapping(mapping) { let newObject = {}; for (let [ key, values ] of Object.entries(mapping)) { for (let value of values) { if (newObject[value] == null) { newObject[value] = []; } newObject[value].push(key); } } return newObject; };