function maxSubArray(a) {
// end::description[]
// tag::solution[]
  let max = -Infinity;
  let local = 0;

  a.forEach((n) => {
    local = Math.max(n, local + n);
    max = Math.max(max, local);
  });

  return max;
}
Find the maximun sum of contiguous elements in an array.

@examples
 maxSubArray([1, -3, 10, -5]); // => 10
 maxSubArray([-3,4,-1,2,1,-5]); // => 6

@param {number[]} a - Array
@returns {number} - max sum