Maximum Subarray Leetcode Solution Javascript