Write a JavaScript program to pad a string on both sides with the specified character, if it's shorter than the specified length
- برمجة جافاسكربت java script
- برمجة
- 2021-06-03
- ahmadghneem
الأجوبة
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))
أسئلة مشابهة
القوائم الدراسية التي ينتمي لها السؤال