1 Star 0 Fork 34

liming0101/outline.js

forked from Yaohaixiao/outline.js 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
_getChaptersWithCode.js 743 Bytes
一键复制 编辑 原始数据 按行查看 历史
Yaohaixiao 提交于 2024-02-28 09:08 . chore: 调整代码可读性
import isArray from './utils/types/isArray'
const _getChaptersWithCode = (chapters) => {
const groups = {}
const cb = (o) => {
return [o.pid]
}
chapters.forEach((o) => {
const group = JSON.stringify(cb(o))
groups[group] = groups[group] || []
groups[group].push(o)
o.index = groups[group].length
if (o.pid === -1) {
o.code = String(o.index)
}
})
Object.keys(groups).forEach((group) => {
groups[group].forEach((c) => {
const subjects = groups[`[${c.id}]`]
if (!subjects || !isArray(subjects)) {
return false
}
subjects.forEach((o) => {
o.code = c.code + '.' + o.index
})
})
})
return chapters
}
export default _getChaptersWithCode
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/liming0101/outline.js.git
[email protected]:liming0101/outline.js.git
liming0101
outline.js
outline.js
master

搜索帮助