Bee AntJared's Blog

FE前端

BE后端

DB数据库

OPS运维

Snippet代码片段

Note笔记

I'm also on

GitHubIf you code

MailIf you talk

RSSIf you subscribe

About.meIf you recommend

Number Repeat snippet


String.prototype.repeat()

/** 
 * str: String
 * count: Number
 */

let resultString = str.repeat(count);

repeat()构造并返回一个新字符串,该字符串包含被连接在一起的指定数量的字符串的副本。

/** 
 * ......
 * 4444
 * 333
 * 22
 * 1
 * 22
 * 333
 * 4444
 * ......
 */
function f(n) {
  for (let i = -n; i <= n; i++) {
    if (i === 0 || i === 1) {
      continue
    }
    let k = Math.abs(i)
    console.log(k.toString().repeat(k))
  }
}