Compare sum of first N | Function that returns true if sum of first n - 1 elements of the array is equal to the last element ; Find the sum of first n - 1 elements of the array ; If sum equals to the last element ; Driver code
function isSumEqual ( ar , n ) { let sum = 0 ; for ( let i = 0 ; i < n - 1 ; i ++ ) sum += ar [ i ] ; if ( sum == ar [ n - 1 ] ) return true ; return false ; } let arr = [ 1 , 2 , 3 , 4 , 10 ] ; let n = arr . length ; if ( isSumEqual ( arr , n ) ) document . write ( " " ) ; else document . write ( " " ) ;