"use strict";

var
    Iterator;

Iterator = (function () {

    return {

        isIterable: function (object) {
            if (object[Symbol.iterator]) {
                return true;
            }

            return false;
        },

        each: function (enumerable, callback, recursive = false) {
            var
                trail = [],
                value,
                children;

            if (Iterator.isIterable(enumerable)) {
                enumerable = Array.from(enumerable);
            }

            if (arguments[3] instanceof Array) {
                trail = arguments[3];
            }

            if (typeof callback === "boolean") {
                callback = recursive;
                recursive = arguments[1];
            }

            Object.keys(enumerable).forEach(function (key) {
                value = enumerable[key];

                if (recursive) {

                    if (value instanceof Node) {
                        children = value.children;
                        if (children.length) {
                            callback(value, key, trail);
                            value = children;
                        }
                    }

                    if (Iterator.isIterable(value)
                        || value.constructor === Object) {
                        // call a function recursively doesn't replace values
                        // of the current loop, neither break it, unless the return instruction is called, but just defines a new
                        // loop with a new value to be run.
                        // debugger
                        Iterator.each(value, callback, recursive, trail.concat(key));
                    } else {
                        callback(value, key, trail);
                    }
                } else {
                    callback(value, key, trail);
                }

            });

        }
    };

})();

@@ -924,29 +924,34 @@
 if (
-value instanceof Node
+Iterator.isIterable(value)
 ) %7B%0A
@@ -979,137 +979,160 @@
    c
-hildren = value.children;%0A                        if (children.length) %7B%0A                            callback(value, key, trail);
+allback(value, key, trail);%0A                    %7D%0A%0A                    if (value instanceof Node) %7B%0A                        if (value.children.length) %7B
 %0A   
@@ -1164,16 +1164,22 @@
 value = 
+value.
 children

refactor iterator