Skip to content

Instantly share code, notes, and snippets.

View pinalbhatt's full-sized avatar
💭
from the desk of Pinal Bhatt

Pinal Bhatt pinalbhatt

💭
from the desk of Pinal Bhatt
View GitHub Profile
@pinalbhatt
pinalbhatt / DeepCompare
Created August 3, 2014 13:20
DeepCompare() // Usage: DeepCompare(obj1, obj2) // Usage: DeepCompare(obj1, obj2, obj3)
function DeepCompare() {
var leftChain, rightChain;
function compare2Objects(x, y) {
var p;
// remember that NaN === NaN returns false
// and isNaN(undefined) returns true
if (isNaN(x) && isNaN(y) && typeof x === 'number' && typeof y === 'number') {
return true;
@pinalbhatt
pinalbhatt / Clone
Last active August 29, 2015 14:04
Clone Object in Javascript
/*
Clone Object in Javascript
*/
function Clone(obj) {
// Handle the 3 simple types, and null or undefined
if (null == obj || "object" != typeof obj) return obj;
// Handle Date
if (obj instanceof Date) {
var copy = new Date();
/*
Javascript
ResolveReferences - To resolve references in JSON object with circular references.
*/
function ResolveReferences(json) {
if (typeof json === 'string')
json = JSON.parse(json);
var byid = {}, // all objects by id
refs = []; // references to objects that could not be resolved