main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
String.prototype.myPadEnd = function(newlength, padding=" "){
  let this_length = this.length;
  let strArray = this.split("")
  if(newlength < this_length) {return strArray.join("");} //improvement needed here
  let paddingArray = padding.split("");
  let paddingCounter = 0;
  for(i = this_length; i < newlength; i++)
  {	strArray.push(paddingArray[paddingCounter]);
    paddingCounter++;
    if(paddingCounter >= paddingArray.length) {paddingCounter = 0}
  }
  return strArray.join("");
} 


console.log('abc'.myPadEnd(10));          // "abc       "
console.log('abc'.myPadEnd(10, "foo"));   // "abcfoofoof"
console.log('abc'.myPadEnd(6, "123456")); // "abc123"
console.log('abc'.myPadEnd(1));           // "abc"
Native Browser JavaScript