var maxSubArray = function(nums) {
let max = nums[0];
let maxEnding = nums[0];
for (let i = 1; i < nums.length; i++) {
maxEnding = Math.max(maxEnding + nums[i], nums[i]);
max = Math.max(maxEnding, max);
}
return max;
};
Maximum Subarray: LeetCode
