Easy JS solution


#1

const maxSubArray = function(A){
let prevMax = A[0];
let bestMax = prevMax;
for(let i=1; i<A.length; i++){
const curMax = maxTillIndexByPrevMax(i, prevMax);
bestMax = Math.max(bestMax, curMax);
prevMax = curMax;
}
return bestMax;

function maxTillIndexByPrevMax(i, prevMax){
return Math.max(A[i], prevMax+A[i]);
}
};