JSFiddle - React, Tailwind, and code Playground

by Darby Rathbone

JavaScript

var starttime1 = Date.now();
var list = []; // ul containing 100 li elements


var i =1;
var node = document.documentElement.firstChild;
while (node) {

    list.push(node);
//    console.log(node.firstChild);
    if (node.firstChild)
    {   node = node.firstChild;
    i++;
    }
    else if(node.nextSibling)
        node = node.nextSibling;
    else
    {
        if (node.parentNode)
        node = node.parentNode.nextSibling;
        
    }
}
console.log(list);
console.log(Date.now()-starttime1);
var starttime2 = Date.now();
var nodetype = ["NULL", "ELEMENT", "ATTRIBUTE", "TEXT", "CDATA", "ENTITY_REFERENCE", "ENTITY", "RROCESSING_INSTRUCTION", "COMMENT", "DOCUMENT", "DOCUMENT_TYPE", "DOCUMENT_FRAGMENT", "NOTATION"];

function getchildrennodes() {
    var b = [];
    b = toArray(arguments, 0);
    for (var c = 0; c < b.length; c++) {
        if (b[c].hasChildNodes && b[c].hasChildNodes()) {
            b = b.concat(toArray(b[c].childNodes))
        }
    }
    return b
}
function toArray(d) {
    var c = -1,
        b = d.length,
        a = Array(b);
    while (++c < b) {
        a[c] = d[c]
    }
    return a
};

var docs = getchildrennodes(document);
console.log(docs);
console.log(Date.now()-starttime2);
function () {
        var root = document.documentElement,
            output = [],
            child = function (x) {
                var a = x.childNodes,
                    b = a.length,
                    c = 0;
                for (c = 0; c < b; c += 1) {
                    if (a[c].nodeType === types || types === 0) {
                        output.push(a[c]);
                    }
                    if (a[c].nodeType === 1) {
                        child(a[c]);
                    }
                }
            };
        if (types === 1 || types === 0) {
            output.push(root);
        }
        child(root);
        return output;
    }