Lodash Library - .invert() method


I am really struggling to write the .invert() method in the Lodash library project. The invert method accepts an object as an argument, then it should loop through the key/value pairs of that object and then invert those key/value pairs and put them into an empty object within the same method. Essentially the new object that gets returned should have all the argument object’s keys as the value pairs, and the values as keys.

Any help much appreciated. I am lost.


Is there anything in particular stopping you?
When you ask for general help about the whole thing then presumably you haven’t had very many thoughts on it yet or there would be more specific things to ask about… So, what do you get as input, what can you do with that, and what out of those things might be useful in moving closer to the output? Or maybe you mean that you haven’t understood what’s being asked for?

sorry, should have been more specific.

I am trying to iterate through the object’s keys, then try to create a variable ‘originalValue’ and set it equal to the value on the current object’s key. From there I am lost and don’t really understand the next steps to set the value on ‘originalValue’ on the empty object ‘invertedObject’ to be the current key.
I have thought about it a lot, but my brain is fried at this point. If any one has any pointers on how to proceed I would be grateful.

invertedObject = {};
for(const x in object){
let originalValue = object;
return invertedObject;

If you have a key and a value you’d add that to the result wouldn’t you?
And there would be nothing else to do after that, so what other steps?
Copy the pairs from one object to another. And flip them while doing so.


Thanks for the pointers!