{"ScriptPreparationCode":"var array_1 = [{id: 1}, {id: 2}, {id: 3}, {id: 4}, {id: 5}];\r\nvar array_2 = [{id: 6}, {id: 7}, {id: 8}];\r\nvar array_3 = [{id: 9}, {id: 10}, {id: 11}, {id: 12}, {id: 13}];\r\n\r\nvar ids_to_check = [1, 5, 8, 6, 11, 3];","TestCases":[{"Name":"test_1","Code":"var joined_array = [\r\n array_1,\r\n array_2,\r\n array_3,\r\n]\r\n\r\n\r\nvar counter = 0;\r\njoined_array.every(array =\u003E {\r\n array.every((object, i) =\u003E {\r\n if (ids_to_check.includes(object.id)) {\r\n array[i] = { ... object, updated: true };\r\n counter\u002B\u002B;\r\n }\r\n return counter \u003E= ids_to_check.length;\r\n });\r\n return counter \u003E= ids_to_check.length;\r\n})","IsDeferred":false},{"Name":"test_2","Code":"// main algorithm\r\n// joining all the sub-arrays into one array\r\nvar joinedArray = [array_1, array_2, array_3];\r\n\r\n// calculating total number of elements from all sub-arrays inside\r\nvar joinedArrayTotalLength = joinedArray.reduce(\r\n (totalLength, subArray) =\u003E (totalLength \u002B= subArray.length),\r\n 0\r\n);\r\n\r\nvar pointer = { arrayIdx: 0, elementIdx: 0 };\r\nvar updatedElementsCounter = 0;\r\n\r\nfor (let i = 0; i \u003C joinedArrayTotalLength; i\u002B\u002B) {\r\n // switching between the sub-arrays if we are out of the previous one\r\n if (pointer.elementIdx \u003E joinedArray[pointer.arrayIdx].length - 1) {\r\n pointer.arrayIdx\u002B\u002B;\r\n pointer.elementIdx = 0;\r\n }\r\n\r\n var currentElement = joinedArray[pointer.arrayIdx][pointer.elementIdx];\r\n\r\n // safe undefined element handling\r\n if (!currentElement) {\r\n i--;\r\n pointer.elementIdx\u002B\u002B;\r\n continue;\r\n }\r\n\r\n // updating element in the source array\r\n if (ids_to_check.includes(currentElement.id)) {\r\n joinedArray[pointer.arrayIdx][pointer.elementIdx] = {\r\n ...currentElement,\r\n updated: true,\r\n };\r\n updatedElementsCounter\u002B\u002B;\r\n }\r\n\r\n if (updatedElementsCounter === ids_to_check.length) {\r\n break;\r\n }\r\n pointer.elementIdx\u002B\u002B;\r\n}","IsDeferred":false}]}