Advertisement
dariys

Untitled

Jun 3rd, 2015
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function deepCompare(o1, o2) {
  2.   var o1t = typeof(o1), o2t = typeof(o2);
  3.   if(o1t!==o2t){
  4.     return false;
  5.   }else{
  6.     if((o1t!=='object' && o2t !=='object') || (o1==null || o2 == null)){
  7.       return o1 === o2;
  8.     }else{
  9.       if(o1.length >= 0 && o2.length >= 0){
  10.         if(o1.length === o2.length){
  11.           return o1.every(function(i1, index){
  12.             return deepCompare(i1, o2[index]);
  13.           });
  14.         }else{
  15.           return false;
  16.         }
  17.       }else{
  18.         if(!o1.length && !o2.length){
  19.           var o1k = Object.keys(o1), o2k = Object.keys(o2);
  20.           if(o1k.length !== o2k.length){
  21.             return false;
  22.           }else{
  23.             return o1k.every(function(k){
  24.               return deepCompare(o1[k], o2[k]);
  25.             });
  26.           }
  27.         }else{
  28.           return false;
  29.         }
  30.       }
  31.     }
  32.   }
  33. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement