comparision

Benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
stack
 const flattenMenuItems = array => {
        const stack = [...array];
        const result = [];

        while(stack.length){
            const next = stack.pop();
            if(Array.isArray(next.items)){
                const {items, ...rest} = next;
                result.push(rest)
                stack.push(...items);
            } else{
                result.push(next)
            }
        }
        
        return result.reverse();
    };
ready
recursion
   const flattenMenuItems = array => {
        
        let result = [];
        array.forEach(function (a) {
            result.push(a);
            if (Array.isArray(a.items)) {
                result = result.concat(flattenMenuItems(a.items));
            }
        });
        return result;
    };
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.