Find the final co | Function to print the final position of the point after traversing through the given directions ; Traversing through the given directions ; If its north or south the point will move left or right ; If its west or east the point will move upwards or downwards ; Returning the final position ; Driver Code
function finalCoordinates ( SX , SY , D ) { for ( let i = 0 ; i < D . length ; i ++ ) { if ( D [ i ] == ' ' ) SY += 1 ; else if ( D [ i ] == ' ' ) SY -= 1 ; else if ( D [ i ] == ' ' ) SX += 1 ; else SX -= 1 ; } let ans = ' ' + ( SX ) . toString ( ) + ' ' + ( SY ) . toString ( ) + ' ' ; document . write ( ans ) ; } let SX = 2 , SY = 2 ; let D = " " ; finalCoordinates ( SX , SY , D . split ( " " ) ) ;