Final cell position in the matrix | function to find the final cell position in the given matrix ; to count up , down , left and cright movements ; to store the final coordinate position ; traverse the command array ; calculate final values ; driver code
function finalPos ( command , n , x , y ) { let cup , cdown , cleft , cright ; let final_x , final_y ; cup = cdown = cleft = cright = 0 ; for ( let i = 0 ; i < n ; i ++ ) { if ( command [ i ] == ' ' ) cup ++ ; else if ( command [ i ] == ' ' ) cdown ++ ; else if ( command [ i ] == ' ' ) cleft ++ ; else if ( command [ i ] == ' ' ) cright ++ ; } final_x = x + ( cright - cleft ) ; final_y = y + ( cdown - cup ) ; document . write ( " " + " " + final_x + " " + final_y + " " ) ; } let command = " " ; let n = command . length ; let x = 3 , y = 4 ; finalPos ( command , n , x , y ) ;