/**
* @param {number[]} nums
* @return {number}
*/
var maxSubArray = function (nums) {
let sum = (max = nums[0])
for (let i = 1; i < nums.length; i++) {
const sumWithCurrent = sum + nums[i]
sum = sumWithCurrent < nums[i] ? nums[i] : sumWithCurrent
max = sum > max ? sum : max
}
return max
}