peterschussheim
9/10/2016 - 11:00 PM

deepEqual

deepEqual

// deepEqual :: (Object, Object) -> Boolean
function deepEqual(a, b) {
    if (a === b) {
        return true;
    }
    if (a == null || typeof a != "object" || b == null || typeof b != "object") {
        return false;
    }
    var propsInA = 0;
    var propsInB = 0;
    
    for (var prop in a) {
        propsInA += 1;
    }
    
    for (var prop in b) {
        propsInB += 1;
        if (!(prop in a) || !deepEqual(a[prop], b[prop])) {
            return false;
        }
    }
    return propsInA == propsInB;
}

var obj = {here: {is: "an"}, object: 2};
deepEqual(obj, obj);

deepEqual(obj, {here: 1, object: 2});

deepEqual(obj, {here: {is: "an"}, object: 2});

deepEqual

This Gist was automatically created by Carbide, a free online programming environment.

You can view a live, interactive version of this Gist here.