Correct solution in JS


#1
maxSubArray: function(A) {
    var maxSum = A[0];
    var currentSum = A[0];
    
    for(var index = 1; index < A.length; index++) {
        if (A[index] > currentSum + A[index]) {
            currentSum = A[index];
        } else {
            currentSum += A[index];
        }
        
        if (currentSum > maxSum) {
            maxSum = currentSum;
        }
    }
    
    return maxSum;
}