Skip to content

勘误:章节 3.2.1,页码 39 #9

@yanhaijing

Description

@yanhaijing

勘误范围:第一次印刷

image

图中红色箭头处 '0' 应该替换为参数 ch,,并在map后面添加join(''),完整代码如下

function leftpad(str, count, ch = '0') {
  return `${[...Array(count)].map((v) => ch).join('')}${str}`.slice(-count);
}

上面代码,在浏览器里能够得到正确的结果,如下图:
image

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions