summaryrefslogtreecommitdiff
path: root/src/util.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/util.js')
-rw-r--r--src/util.js20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/util.js b/src/util.js
index 8b85ba7..74233f4 100644
--- a/src/util.js
+++ b/src/util.js
@@ -21,3 +21,23 @@ export function pairs(arr1, arr2) {
.map((x, i) => arr2.map(y => [x, y]))
.flat();
}
+
+
+export function deepEqual(a, b, debug=false) {
+ if (typeof(a) === 'object') {
+ if (typeof(b) === 'object') {
+ // do deep equality
+ return [...new Set(Object.keys(a).concat(Object.keys(b)))].reduce(
+ (acc, key) => {
+ return acc && deepEqual(a[key], b[key]);
+ },
+ true
+ );
+ } else {
+ // one object, one non-object
+ return false;
+ }
+ } else {
+ return a === b;
+ }
+}