Lodash pad()

I cannot figure out why my code does not past the test for the pad() function in the Lodash exercise. Below is my code. The error I get is that the ’ '.repeat(endPaddingLength) has an invalid count value

pad (str, len) {
    if (str.length <= len){
      return str;
    };
    const startPaddingLength = Math.floor((len - str.length)/2);
    const endPaddingLength = len - str.length - startPaddingLength;
    const paddedString =' '.repeat(startPaddingLength) + str + ' '.repeat(endPaddingLength);
    return paddedString;
  },

Seems printing of important variables is the advisable debugging strategy.

Is this not counter to the goal?

1 Like