4 ms·
Most of the reason it's more complicated is because I made it return arrays when recursing and only join at the end because that probably doesn't need as many a
by easrng 5y ago
Most of the reason it's more complicated is because I made it return arrays when recursing and only join at the end because that probably doesn't need as many allocations. The rest of the complication is because the DOM has separate text nodes and the library you're using doesn't seem to. (Oh, and also NodeLists don't have .map so we use the .map from the array prototype) Here's a non-optimized version:
let getText = n =>[].map.call(n.childNodes,e => e.nodeType == 3 ? e.data : getText(e)).join("")
- kragen 5y agoRight, I'm saying I think the statically-typed ElementTree approach is superior to the dynamically-typed approach used by the W3C DOM.