Find an array element such that all elements are divisible by it | function to find smallest num ; traverse for all elements ; stores the minimum if it divides all ; Driver code
function findSmallest ( a , n ) { for ( let i = 0 ; i < n ; i ++ ) { let j ; for ( j = 0 ; j < n ; j ++ ) if ( a [ j ] % a [ i ] >= 1 ) break ; if ( j == n ) return a [ i ] ; } return - 1 ; } let a = [ 25 , 20 , 5 , 10 , 100 ] ; let n = a . length ; document . write ( findSmallest ( a , n ) ) ;