JSFiddle - React, Tailwind, and code Playground
by Farzad YZ
JavaScript
/* Problem #2: Write a function that receives a object as the argument and inverts it.
Example: */
const map = {
a: ["z"],
b: ["x", "y"],
c: ["w", "z"]
};
/* Invert(map); ==> {
z: [‘a’, ‘c’],
x: [‘b’],
y: [‘b’],
w: [‘c']
} */
function invert(object) {
const newObject = {};
const objKeys = Object.keys(object);
objKeys.map(key => newObject[object[key]] = key )
console.log(newObject)
return newObject
}
invert(map)