Lodash Project - Pad

pad(str, len) {
    if (str.length >= len) {
      return str;
    let startPad = Math.floor(len - str.length / 2);
    let endPad = (len - str.length) - startPad;
    let paddedStr = ' '.repeat(startPad) + str + ' '.repeat(endPad);
    return paddedStr;

Can anyone please explain why this is returning an error that says the second .repeat() not a valid count?

RangeError: Invalid count value
at String.repeat ()
at Object.pad (/home/ccuser/workspace/underscore-javascript-capstone/_.js:31:54)
at Object. (/home/ccuser/workspace/underscore-javascript-capstone/test/pad.js:15:79)

I can’t tell what is wrong with my code as it looks like i have written it correctly. thanks in advance.

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