Re-Creating the Lodash Library

const _ = {
clamp (number, lower, upper){
const lowerClampedValue = Math.max(number, lower);
const clampedValue = Math.min(lowerClampedValue, upper);
return clampedValue;
}
};

// Do not write or modify code below this line.
module.exports = _;

HELLO ALL,

SOME HELP WITH THE ABOVE PLEASE. I AM ON THE RE-CREATING LODASH SECTION, JUST ON THE FIRST ONE ‘CLAMPS’, EVERY TIME I TEST IT BRINGS AN ERROR:

1 - _.clamp() is defined - Failed: _.clamp() was not properly defined.

I HAVE NO IDEA WHY THIS IS, I HAVE TRIED USING VAR, LET AND CONST. THE WALKTHRU USES VAR SO THAT’S WHAT IVE DONE, I HAVE CHECKED AND I LITERALLY HAVE THE SAME SCRIPT AS THE WALKTHRU, BUT I AM STILL GETTING THE ERROR?

HELP PLEASE!!!

MANY THANKS
DEAN

Be sure to Save before running the test.

3 Likes

Hi there,
I have a problem with the .invert() method in Lodash project.

I wrote this:
invert(object){
let invertedObject = {};
for(let key in object){
const originalValue = object[key];
invertedObject = {originalValue: key};
}
return invertedObject;
}

First 3 went great, but then it returns this error:
4 - Returns an object with all keys and values inverted - Failed: _.invert({originalKey: “originalValue”})[“originalKey”]) returned undefined instead of anotherKey.

I even watched the project walkthrough, checked it and saved it, but I still can’t figure it out.
Please help me!

Thank you,
Mathe :slight_smile:

1 Like

That return value will contain only one key, and one value. You are creating a new object on each iteration.

1 Like

Can you elaborate on this a little? I’m having the exact same problem and I’m confused because I even tried watching the walk-through and then copying her code verbatim but still got the same error.

I think I understand what you’re saying the problem is… But how would you fix it?

1 Like

Never mind. I fixed it!! Your original comment was enough to help me dig around and figure it out. Thank you. I really appreciate it!

1 Like

hi im stuck on the same problem. can u show me how did u fixed it?
i did this but it keeps showing error:

invert(object) {
let invertedObject = {};
let key;
for(key in object) {
let originalValue = object[key] ;}
invertedObject.originalValue = key
return invertedObject;

}

Looks like you have some unnecessary curly braces in there after your ‘for’ statement.

For reference, here’s what I did:

invert (object) {
      let invertedObject = {};
      for (let key in object){
        const originalValue = object[key];
        invertedObject[originalValue] = key;
      }
      return invertedObject;
},