Find the final number obtained after performing the given operation | Function to return the final number obtained after performing the given operation ; Find the gcd of the array elements ; Driver code
function finalNum ( arr , n ) { var result = 0 ; for ( i = 0 ; i < n ; i ++ ) { result = __gcd ( result , arr [ i ] ) ; } return result ; } function __gcd ( a , b ) { return b == 0 ? a : __gcd ( b , a % b ) ; } var arr = [ 3 , 9 , 6 , 36 ] ; var n = arr . length ; document . write ( finalNum ( arr , n ) ) ;