Q:

Write a JavaScript program to pad a string on both sides with the specified character, if it's shorter than the specified length

0

Write a JavaScript program to pad a string on both sides with the specified character, if it's shorter than the specified length

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

onst pad = (str, length, char = ' ') =>
 str.padStart((str.length + length) / 2, char).padEnd(length, char);
console.log(pad('cat', 8));
console.log(pad(String(42), 6, '0'))
console.log(pad('foobar', 3))

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now