Lodash object project

how can i set a variable in object please , i get stuck in the method of invert()






// Do not write or modify code below this line.

const _ = {

invert(object) {
  let inter = 0
   let invertedObject = {}
  for(let property in object) {
   

    let originalValue = property
    let originalKey = object[property]
 invertedObject = {originalKey = originalValue}
  }
return invertedObject
}
}
console.log(_.invert({'name': 'bodreza', 'age': 15}))
module.exports = _;

I believe you have originalValue and originalKey mixed up. When you are looping through an object with for … in as you are doing then the variable you have as property will refer to the original keys and the values can be accessed with object[property]. There is also a problem with the syntax of this line:

invertedObject = {originalKey = originalValue}

Try something like this then you can skip the originalValue/originalKey assignments:

invertedObject[object[property]] = property;
1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.