Position after taking N steps to the right and left in an alternate manner | Function to return the last destination ; Driver Code
function lastCoordinate ( n , a , b ) { return ( parseInt ( n + 1 ) / 2 ) * a - parseInt ( n / 2 ) * b ; } let n = 3 , a = 5 , b = 2 ; document . write ( lastCoordinate ( n , a , b ) ) ;