Hello, I’m still working on the Lodash lesson and down to step 25.
Assuming that the object parameter is in a similar format to that which was outlined in this post
var object = { ‘a’: 1, ‘b’: 2, ‘c’: 1 };
When finished, the output should look like:
{1: ‘a’, 2: ‘b’ 1: ‘c’}
Given the above, this is what I came up with after reviewing other posts and reviewing my copious notes from prior lessons:
// step 23 - 26 .invert method
invert(object){
const invertedObject = {}
for(let key in object){
const originalValue = object[key]
object[key] = object[value]
object[value] = originalValue
//invertedObject = {originalValue: key}
}
return invertedObject
}//closes the invert method
I can’t figure out how to ‘grab’ the key Vs value from the combined property. Looking at another student’s work posted on this forum, I copied object[key]
assuming that this allows me to grab the key of the object. I probably wrongly assumed that object[value]
is the way to get the corresponding value. I have no idea why const invertedObject={}
had to be added to the code.
Also, I saw that mtf used invertedObject = {originalValue: key}
in this post, which introduced more strange syntax to me that I just don’t recall ever seeing and can’t find in my notes.
I’m embarrassed to say that I’m just completely lost. Probably before I attempt to figure out this lesson, I need to be sent off to review a past lesson to refresh my memory…
Thank you for your insight.