text: Minimum number of steps required to reach origin from a given point | Function to find the minimum moves required to reach origin from ( a , b ) ; Stores the minimum number of moves ; Check if the absolute difference is 1 or 0 ; Store the minimum of a , b ; Store the maximum of a , b ; Print the answer ; Given co - ordinates ; Function Call
code: function findMinMoves ( a , b ) { let ans = 0 ; if ( a == b || Math . abs ( a - b ) == 1 ) { ans = a + b ; } else { let k = Math . min ( a , b ) ; let j = Math . max ( a , b ) ; ans = 2 * k + 2 * ( j - k ) - 1 ; } document . write ( ans ) ; } let a = 3 , b = 5 ; findMinMoves ( a , b ) ;