make sure undefined valeus are weeded out first

Signed-off-by: Oleg S <97077423+RobotSail@users.noreply.github.com>
This commit is contained in:
Oleg S
2023-03-02 09:34:00 -05:00
parent bf828dea7f
commit 1fbb7e6807
+7 -7
View File
@@ -76,13 +76,6 @@ export const mergeJson = (a: JsonObject, b: JsonObject): JsonObject => {
// for all primitives and arrays, we want to assign the value from b
// for all objects, we want to recursively merge the values
for (const key of intersectingKeys.values()) {
// check if value is an array or primitive
const value = b[key];
if (Array.isArray(value) || typeof value !== 'object') {
final[key] = value;
continue;
}
// check if either value is undefined and default to the defined one
const aValue = a[key];
const bValue = b[key];
@@ -95,6 +88,13 @@ export const mergeJson = (a: JsonObject, b: JsonObject): JsonObject => {
continue;
}
// check if value is an array or primitive
const value = bValue;
if (Array.isArray(value) || typeof value !== 'object') {
final[key] = value;
continue;
}
// recursively merge the values
final[key] = mergeJson(aValue as JsonObject, bValue as JsonObject);
}