Friday, April 8, 2016

Append characters to the end of a string

function appendString(length, StringToAppendTo, appendStringWith) {
  var returnString = ""

  returnString += StringToAppendTo;

  if (StringToAppendTo.length < length) {
    for (var i = 0; i < length - 1; i++) {
      returnString += appendStringWith;
    }
  }

  return returnString;
}

Use it like this:

var appendedString = appendString(2, "1", "0");

No comments:

Post a Comment