Lodash invert.js failed on last test

Hi

I am stuck on this task, keep getting failed message on the last test. Please check what i am doing wrong

My Code

invert(obj){
    const invertedObject = {};
    for(key in obj){
      let originalValue = obj[key];
      //invertedObject = {originalValue: key};
      invertedObject.originalValue = key;
    }
    return invertedObject;
  }

Thanks

Hi, I just made that task, and was stuck for a few hours; even saw the video and the code that appears there fail the tests.

This is the code that work for me

invert(obj) {
    let invertedObject = {};
    let oValue;
    for (key in obj) {
      oValue = obj[key];
      invertedObject[oValue] = key;
    }
    return invertedObject;
  }

Cheers it worked Thanks

correct way is the following line

> invertedObject[oValue] = key;

Following was my wrong syntax
invertedObject.originalValue = key;

Thanks

Don’t forget it’s important to figure out why your code didn’t work! It’s not enough to just get the answer and move on.

Hi

Reason is the following code is the right syntax to access the value of a property from an object workedinvertedObject[oValue]

Thanks

1 Like

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