Created
February 3, 2015 14:14
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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