Find the vertex diagonally opposite to the vertex M from an N | Function to return the required vertex ; Case 1 : ; Case 2 : ; Driver Code
function getPosition ( N , M ) { if ( M > parseInt ( N / 2 ) ) { return ( M - parseInt ( N / 2 ) ) ; } return ( M + parseInt ( N / 2 ) ) ; } var N = 8 , M = 5 ; document . write ( getPosition ( N , M ) ) ;