{"ScriptPreparationCode":"// Create an array of 1000 random intergers between 1 and 10000\r\nvar arrRandom = [];\r\nfor(var intCtr=0; intCtr\u003C1000; intCtr\u002B\u002B) {\r\n arrRandom.push(Math.floor(Math.random() * Math.floor(10000)));\r\n}\r\n\r\nfunction reduceCallback(accum, curr) {\r\n\treturn accum\u002Bcurr;\r\n}\r\n\r\nfunction doRedeuce(pArray) {\r\n\treturn pArray.reduce(reduceCallback);\r\n}\r\nfunction doLoop(pArray) {\r\n\tvar accum = 0;\r\n\tfor(var intCtr=0; intCtr\u003CpArray.length; intCtr\u002B\u002B) {\r\n\t\taccum \u002B= pArray[intCtr];\r\n\t}\r\n\treturn accum;\r\n}\r\nfunction doForEach(pArray) {\r\n\tvar accum = 0;\r\n\tpArray.forEach(function(item) {\r\n\t\taccum \u002B= item;\r\n\t});\r\n}\r\n\r\nfunction baseEach(collection, iteratee) {\r\n if (collection == null) {\r\n return collection\r\n }\r\n if (!isArrayLike(collection)) {\r\n return baseForOwn(collection, iteratee)\r\n }\r\n const length = collection.length\r\n const iterable = Object(collection)\r\n let index = -1\r\n\r\n while (\u002B\u002Bindex \u003C length) {\r\n if (iteratee(iterable[index], index, iterable) === false) {\r\n break\r\n }\r\n }\r\n return collection\r\n}\r\nfunction lodashReduce(collection, iteratee, accumulator) {\r\n const func = Array.isArray(collection) ? arrayReduce : baseReduce\r\n const initAccum = arguments.length \u003C 3\r\n return func(collection, iteratee, accumulator, initAccum, baseEach)\r\n}\r\nfunction arrayReduce(array, iteratee, accumulator, initAccum) {\r\n let index = -1\r\n const length = array == null ? 0 : array.length\r\n\r\n if (initAccum \u0026\u0026 length) {\r\n accumulator = array[\u002B\u002Bindex]\r\n }\r\n while (\u002B\u002Bindex \u003C length) {\r\n accumulator = iteratee(accumulator, array[index], index, array)\r\n }\r\n return accumulator\r\n}\r\nfunction doLodashReduce (pArray) {\r\n return lodashReduce(pArray, reduceCallback)\r\n}","TestCases":[{"Name":"reduce","Code":"var redeuceResult=0;\r\nredeuceResult = doRedeuce(arrRandom);","IsDeferred":false},{"Name":"for loop","Code":"var loopResult=0;\r\nloopResult = doLoop(arrRandom);","IsDeferred":false},{"Name":"forEach ","Code":"var forEachResult=0\r\nforEachResult = doForEach(arrRandom)","IsDeferred":false},{"Name":"lodash.reduce","Code":"var lodashReduceResult = doLodashReduce(arrRandom)","IsDeferred":false}]}