Find the minimum possible health of the winning player | Function to return the minimum possible health of the last player ; Find the GCD of the array elements ; Driver code
function minHealth ( health , n ) { var gcd = 0 ; for ( var i = 0 ; i < n ; i ++ ) { gcd = __gcd ( gcd , health [ i ] ) ; } return gcd ; } function __gcd ( a , b ) { return b == 0 ? a : __gcd ( b , a % b ) ; } var health = [ 5 , 6 , 1 , 2 , 3 , 4 ] ; var n = health . length ; document . write ( minHealth ( health , n ) ) ;