1 Star 0 Fork 0

艷華/dataStructuresAndAlgorithms

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
生成目录.js 1009 Bytes
一键复制 编辑 原始数据 按行查看 历史
zengyanhua 提交于 2021-10-07 11:49 . chore:生成目录、手写promise
const input = ['# a', '## b', '## c', '### d', '# e']
const getOutPut = (input) => {
let hn = ''
return input.reduce((res, cur) => {
const [symbol, title] = cur.split(' ')
if (hn) {
const hnList = hn.split('.')
console.log(symbol, hnList)
if (symbol.length < hnList.length) {
hn = '' + (+hnList[0] + 1)
} else if (symbol.length > hnList.length) {
hn += '.1'
} else {
const last = hnList.pop()
hn = hnList.join('.') + '.' + (+last + 1)
}
} else {
hn = '1'
}
res.push({ hn, title })
return res
}, [])
}
// console.log(getOutPut(input))
// const promise = new Promise((resolve, reject) => {
// console.log(1)
// resolve()
// console.log(2)
// })
// promise.then(() => {
// console.log(3)
// })
// console.log(4)
Promise.resolve(1).then(2).then(Promise.resolve(3)).then(console.log)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zyhua/dataStructuresAndAlgorithms.git
git@gitee.com:zyhua/dataStructuresAndAlgorithms.git
zyhua
dataStructuresAndAlgorithms
dataStructuresAndAlgorithms
master

搜索帮助