Largest number dividing maximum number of elements in the array | Function to return the largest number that divides the maximum elements from the given array ; Finding gcd of all the numbers in the array ; Driver code
function findLargest ( arr , n ) { var gcd = 0 ; for ( i = 0 ; i < n ; i ++ ) gcd = __gcd ( arr [ i ] , gcd ) ; return gcd ; } function __gcd ( a , b ) { return b == 0 ? a : __gcd ( b , a % b ) ; } var arr = [ 3 , 6 , 9 ] ; var n = arr . length ; document . write ( findLargest ( arr , n ) ) ;