JSFiddle - React, Tailwind, and code Playground
by mathheadinclouds
HTML
1<div id='div1'></div>
2<div id='div2'></div>
3<div id='div3'></div>
4<div id='div4'></div>
5<div id='div5'></div>
6<div id='div6'></div>
7<div id='div7'></div>
8<div id='div8'></div>
9<div id='div9'></div>
0<div id='div0'></div>
JavaScript
function deepEqual(item1, item2){
var EQUAL_ATOM = 1, UNEQUAL = 2, SPECIAL_OBJ = 3, GENERAL_OBJ = 4;
function compareSimple(first, second){
var ty1 = typeof first, ty2 = typeof second;
if (ty1!==ty2) return UNEQUAL;
if (ty1!=='object'){
if (first===second) return EQUAL_ATOM;
if ((ty1==='number')&&isNaN(first)&&isNaN(second)) return EQUAL_ATOM;
return UNEQUAL;
}
if (first===null) return (second===null) ? EQUAL_ATOM : UNEQUAL;
if (second===null) return UNEQUAL;
var inst1, inst2;
inst1 = first instanceof Date ; inst2 = second instanceof Date ; if (inst1!==inst2) return UNEQUAL; if (inst1) return (first-second===0) ? SPECIAL_OBJ : UNEQUAL;
inst1 = first instanceof RegExp; inst2 = second instanceof RegExp; if (inst1!==inst2) return UNEQUAL; if (inst1) return (first.toString()===second.toString()) ? SPECIAL_OBJ : UNEQUAL;
if (Object.getPrototypeOf(first) !== Object.getPrototypeOf(second)) return UNEQUAL;
return GENERAL_OBJ;
}
var c = compareSimple(item1, item2);
if (c !== GENERAL_OBJ) { return (c!==UNEQUAL); }
var stack1 = [], stack2 = [], inverse1 = new Map(), inverse2 = new Map();
stack1.push(item1); stack2.push(item2);
inverse1.set(item1, 0); inverse2.set(item2, 0);
var currentIdx = 0;
var firstItem, secondItem, i, own, has1, has2, key, kid1, kid2, itemCount;
var specialObjCount = 0;
while (currentIdx < stack1.length){
firstItem = stack1[currentIdx]; secondItem = stack2[currentIdx];
own = {};
for (key in firstItem){
has1 = firstItem.hasOwnProperty(key);
has2 = secondItem.hasOwnProperty(key);
if (has1 !== has2) return false;
if (has1) { own[key] = null; }
}
for (key in secondItem){
if (!(key in own)){
has1 = firstItem.hasOwnProperty(key);
has2 =...