Lodash Project - pad()

Hello everyone,

I’m stuck at this step of the Lodash project where pad is implemented. I keep encountering a range error and can’t seem to fix this one. When I tried running the function in playcode or jsfiddle, everything seems to be working fine. Would appreciate the help!

    pad(string, length) {
      if (string >= string.length) {
        return string;
    const startPaddingLength = Math.floor((length - string.length) / 2);
    const endPaddingLength = length - string.length - startPaddingLength;
    const paddedString = ' '.repeat(startPaddingLength) + string + ' '.repeat(endPaddingLength);
    return paddedString;

Never mind! Solved it. Thanks!

Are you embarrassed? Good. Remember that feeling. We’ve all had it; and, repeatedly.

1 Like

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