From 73ab7cfff8b14d0fe42b16f9ccaaa7d386c6fdbd Mon Sep 17 00:00:00 2001 From: Jonas Tamimi Date: Mon, 11 Dec 2023 16:58:34 +0100 Subject: [PATCH] Fixed builder merge algorithm --- client/src/components/json/json-builder-converter.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/client/src/components/json/json-builder-converter.js b/client/src/components/json/json-builder-converter.js index 230363b..65d0169 100644 --- a/client/src/components/json/json-builder-converter.js +++ b/client/src/components/json/json-builder-converter.js @@ -153,8 +153,11 @@ export default { const mergedArray = []; - for (let i = 0; i < existingElements.length; i++) { - mergedArray.push(this.merge(JSON.parse(JSON.stringify(existingElements[i])), updateElements[useFirstUpdateElement ? 0 : i])); + const length = Math.max(existingElements.length, updateElements.length); + for (let i = 0; i < length; i++) { + const existingElement = existingElements[i] === undefined ? (useFirstUpdateElement ? existingElements[0] : undefined) : JSON.parse(JSON.stringify(existingElements[i])); + const updateElement = updateElements[i] === undefined ? (useFirstUpdateElement ? updateElements[0] : undefined) : updateElements[i]; + mergedArray.push(this.merge(existingElement, updateElement)); } return {