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
  • برمجة

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

الأجوبة

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))
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...