Advertisement
Guest User

Untitled

a guest
Nov 15th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function compareObj(lobj, robj, cb){
  2.     if (typeof lobj != typeof robj){
  3.         return cb(null, false);
  4.     }
  5.     if (typeof lobj == 'object'){
  6.         if (lobj instanceof Array && !robj instanceof Array){
  7.             return cb(null, false);
  8.         }
  9.         if (!lobj instanceof Array && robj instanceof Array){
  10.             return cb(null, false);
  11.         }
  12.         if (lobj instanceof Array && robj instanceof Array){
  13.             if (lobj.length != robj.length){
  14.                 return cb(null, false);
  15.             }
  16.             else{
  17.                 let compareResult = true;
  18.                 for (let idx in lobj){                    
  19.                     compareObj(lobj[idx], robj[idx], (err, result) => {
  20.                         if (!result){
  21.                             compareResult = result;                            
  22.                         }
  23.                     })  
  24.                     if (compareResult == false){
  25.                         break;
  26.                     }                  
  27.                 }
  28.                 return cb(null, compareResult);
  29.             }            
  30.         }
  31.         else{
  32.             let compareResult = true;
  33.             for (let key in lobj){
  34.                 if (!key in robj){
  35.                     compareResult = false;
  36.                     break;
  37.                 }
  38.                 else{
  39.                     compareObj(lobj[key], robj[key], (err, result) => {
  40.                         if (!result){
  41.                             compareResult = result;                            
  42.                         }
  43.                     })    
  44.                 }
  45.                 if (compareResult == false){
  46.                     break;
  47.                 }
  48.             }  
  49.             return cb(null, compareResult);        
  50.         }
  51.     }
  52.     else{
  53.         return cb(null, lobj === robj);
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement