From ce4c14bb8f64dacaedf7ffebc04629fd6e84b04f Mon Sep 17 00:00:00 2001 From: Akash Singh Date: Wed, 19 Mar 2025 14:55:42 -0700 Subject: [PATCH] Added accumulator to track comparisions of each key when comparing objects --- shared/json_utilities.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/shared/json_utilities.go b/shared/json_utilities.go index e7ce467..8f4c78e 100644 --- a/shared/json_utilities.go +++ b/shared/json_utilities.go @@ -52,17 +52,19 @@ func IsSubset(json, superSet interface{}) bool { // isMapSubset Helper function to check if objOne (map[string]interface{}) is a subset of objTwo func isMapSubset(objOne, objTwo map[string]interface{}) bool { + // Accumulator to check if all key-value pairs in objOne exist in objTwo + objMatches := true for key, valueObjOne := range objOne { // Check if the key exists in objTwo if valueObjTwo, exists := objTwo[key]; exists { // Recursively check if the values are deeply equal - return IsSubset(valueObjOne, valueObjTwo) + objMatches = objMatches && IsSubset(valueObjOne, valueObjTwo) } else { // Key doesn't exist in objTwo return false } } - return true + return objMatches } // isSliceSubset Helper function to check if arrOne ([]interface{}) is a subset of arrTwo