I implemented the .pad method as follows. This is part of the “Java Syntax, Part II (Lodash)” exercise. The functions works perfectly well in my VS Studio Code, but not on CodeCademy. I chose to use the string methods .padStart and .padEnd instead of repeat(). For whatever reason, CodeCademy says str.padStart is not a function.
_.pad = function(str, len) {
if (str.length >= len) {
return str;
} else {
let strPadding = Math.floor((len - str.length) /2);
return str.padStart(str.length + strPadding).padEnd(len);
}
}