Find the good permutation of first N natural numbers | Function to print the good permutation of first N natural numbers ; If n is odd ; Otherwise ; Driver code
function printPermutation ( n ) { if ( n % 2 != 0 ) document . write ( - 1 ) ; else for ( let i = 1 ; i <= Math . floor ( n / 2 ) ; i ++ ) document . write ( ( 2 * i ) + " " + ( ( 2 * i ) - 1 ) + " " ) ; } let n = 4 ; printPermutation ( n ) ;