JS solution easy and working

amazon
Tags: #<Tag:0x00007f18226fd588>

#1

module.exports = {
//param A : array of integers
//return an integer
maxSubArray : function(A) {
var maxSum = -10000;
var currentSum = 0;
for (var i = 0; i < A.length; i++) {
if (A[i] == 0) {
continue;
}
currentSum = currentSum+A[i];
maxSum = Math.max(currentSum, maxSum);
if (currentSum < 0) {
currentSum = 0;
}
}

    return maxSum;
}

};