function to find the maximum sum that exists in a subarray
function maxSubArraySum ( arr , size ) { var max_so_far = arr [ 0 ] ; var curr_max = arr [ 0 ] ; for ( var i = 1 ; i < size ; i ++ ) { curr_max = Math . max ( arr [ i ] , curr_max + arr [ i ] ) ; max_so_far = Math . max ( max_so_far , curr_max ) ; } return max_so_far ; }