Recreating the lodash library

I am getting an error when implementing the pad() method within lodash, it refers to the use of repeat within the method,

The error is related to the following line:

const paddedString =' '.repeat(startPaddingLength) + str + ' '.repeat(endPaddingLength);

The error states:

RangeError: Invalid count value at String.repeat

I tested the line of code you posted, and see no problems with it specifically. Will need to see the rest of the code in order to help.

1 Like

Not to worry, I managed to make it work in the end

1 Like

how did you fix it?
Iā€™m getting the same error.

  1. Add the .clamp() method to the lodash object.
  2. Use Math.max() to clamp the number by the lower bound. The return value of Math.max() called with the number and the lower bound will be the larger of the two values, meaning it will be clamped by the lower bound.
  3. Use Math.min() to clamp the number by the upper bound. The return value of Math.min() called with the number and the upper bound will be the smaller of the two.
  4. Return the final value of these two operations, which will be the clamped number.

Can someone please translate these instructions into English for me please?

Thank you.