O(n).js 241 B

123456789101112131415161718
  1. 'use strict';
  2. module.exports = function (str, len, ch) {
  3. str = str + '';
  4. len = len - str.length;
  5. if (len <= 0) return str;
  6. if (!ch && ch !== 0) ch = ' ';
  7. ch = ch + '';
  8. while (len--) {
  9. str = ch + str;
  10. }
  11. return str;
  12. }