Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function compareObj(lobj, robj, cb){
- if (typeof lobj != typeof robj){
- return cb(null, false);
- }
- if (typeof lobj == 'object'){
- if (lobj instanceof Array && !robj instanceof Array){
- return cb(null, false);
- }
- if (!lobj instanceof Array && robj instanceof Array){
- return cb(null, false);
- }
- if (lobj instanceof Array && robj instanceof Array){
- if (lobj.length != robj.length){
- return cb(null, false);
- }
- else{
- let compareResult = true;
- for (let idx in lobj){
- compareObj(lobj[idx], robj[idx], (err, result) => {
- if (!result){
- compareResult = result;
- }
- })
- if (compareResult == false){
- break;
- }
- }
- return cb(null, compareResult);
- }
- }
- else{
- let compareResult = true;
- for (let key in lobj){
- if (!key in robj){
- compareResult = false;
- break;
- }
- else{
- compareObj(lobj[key], robj[key], (err, result) => {
- if (!result){
- compareResult = result;
- }
- })
- }
- if (compareResult == false){
- break;
- }
- }
- return cb(null, compareResult);
- }
- }
- else{
- return cb(null, lobj === robj);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement