Skip to content

Instantly share code, notes, and snippets.

@qmacro
Created February 3, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qmacro/ec37431c29e2be889633 to your computer and use it in GitHub Desktop.
Save qmacro/ec37431c29e2be889633 to your computer and use it in GitHub Desktop.
Test equality of record structures as maps, in JavaScript, using reduce. Assuming maps have same structure.
var map1 = {name: "DJ", colour: "green"};
var map2 = {name: "DJ", colour: "green"};
Object.keys(map1).reduce(function(bool, prop) {
return bool && map1[prop] === map2[prop];
}, true); // => true
map2.name = "Joseph";
Object.keys(map1).reduce(function(bool, prop) {
return bool && map1[prop] === map2[prop];
}, true); // => false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment