/** * @param {number[]}A * @return {boolean} */ var canThreePartsEqualSum = function(A) { var total = A.reduce((result, next) => { result += next; return result; }, 0); var average = total / 3; var i = -1; var j = -1; var tempTotal = 0;
for (var k = 0; k < A.length; k++) { tempTotal += A[k]; if (tempTotal === average && i === -1) { i = k; tempTotal = 0; } elseif (tempTotal === average && i !== -1 && k !== A.length - 1) { returntrue; } } returnfalse; };