Find minimum GCD of all pairs in an array | JavaScript program to find the minimum GCD of any pair in the array ; Function returns the Minimum GCD of any pair ; Finding GCD of all the elements in the array . ; Driver code
function calGCD ( a , b ) { if ( ! b ) { return a ; } return calGCD ( b , a % b ) ; } function MinimumGCD ( arr , n ) { var g = 0 ; var i ; for ( i = 0 ; i < n ; i ++ ) { g = calGCD ( g , arr [ i ] ) ; } return g ; } var arr = [ 2 , 4 , 6 , 8 , 3 ] ; var N = arr . length ; document . write ( MinimumGCD ( arr , N ) ) ;