写出给定DOM的深度,大家有什么好的写法没,稍微具体一下,比递归深一点的。大神不吝赐教啊
来自酷炫的 CNodeMD
https://stackoverflow.com/questions/33903929/iterate-throught-html-dom-and-get-depth
补充: LZ 想要的可能是下面这个
(f => (x => f(y => x(x)(y))) (x => f(y => x(x)(y))) ) (get => node => Array.from(node.childNodes) .filter(node => node.nodeType === Node.ELEMENT_NODE) .reduce((depth, node) => Math.max(depth, get(node) + 1), 1) ) (document.documentElement)
原地址
@ianchn 大神厉害了,愣是看不懂
@FantasyGao 不是我写的,看原地址,这个是比递归深一点的匿名函数递归。。。
CNode 社区为国内最专业的 Node.js 开源技术社区,致力于 Node.js 的技术研究。
https://stackoverflow.com/questions/33903929/iterate-throught-html-dom-and-get-depth
补充: LZ 想要的可能是下面这个
原地址
@ianchn 大神厉害了,愣是看不懂
来自酷炫的 CNodeMD
@FantasyGao 不是我写的,看原地址,这个是比递归深一点的匿名函数递归。。。