Project lodash

I came across this project lodash somehow and I was wondering what the point of it is?
I was reading the instructions and I’m not sure when I’m suppose to start coding but I started during step 3 already and here’s what I got

const _ = {
    clamp(number, lowBound, upperBound) {
        // // my solution for readability
        // if (number < lowBound) {
        //     return lowBound;
        // } else if (number > upperBound) {
        //     return upperBound;
        // } else if (number > lowBound && number < upperBound) {
        //     return number;
        // }

        // // my solution for clean code
        // return (number < lowBound) ? lowBound : (number > upperBound) ? upperBound : (number > lowBound && number < upperBound) ? number : false;

        // // my solution using Math Object
        // const clampLow = Math.max(number,lowBound);
        // const clampUpper= Math.min(clampLow,upperBound);
        // return clampUpper;

        // my solution using Math Object but in one line
        return Math.min(Math.max(number,lowBound),upperBound);
    }
};


const test1 = _.clamp(10,-5,5);
const test2 = _.clamp(-10,-5,5);
const test3 = _.clamp(0,-5,5);
console.log(test1);
console.log(test2);
console.log(test3);
// Do not write or modify code below this line.
module.exports = _;

I was looking at the walkthrough when I finished and tested my code and the solution code instead uses

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

Is there a difference? and is there a preference in the industry?

I had 2 solutions for mine as shown above without looking past step 3 I just coded how it was described. Should I use the:
// my solution for readability code
or
// my solution for clean code
or
// walkthrough code from the video?
or
// my solution using Math Object but in one line

It is a project so you can use whatever code you like as longs as it works. Have you tested it?

There is no right or wrong answer when it comes to programming. As a result, don’t be frustrated if the solution we present is different than the solution you came up with. We are merely trying to challenge you to consider many different solutions. Your solution is equally as valid as ours. Consider the one you were going to write and then consider ours. Whichever you pick in the end is completely your decision, and we support it completely.

To what I can see, you seem to have a higher understanding of Javascript over what is needed for the project. Your methodology of using shorthand notations and existing methods, and questioning what code to use, shows this.

It is up to you to see whether this project is challenging you enough, if not, see if you can find a way how to make things more challenging, and if that doesn’t work, then this course may not be for you…

2 Likes