forked from akshitagit/JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhfc.js
More file actions
43 lines (30 loc) · 604 Bytes
/
hfc.js
File metadata and controls
43 lines (30 loc) · 604 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//numbers = [2, 4, 6]
//~ numbers = [54, 24]
//numbers = [15, 25, 35]
function hcf(vector){
min_number = get_min_number(vector)
for( hcf = min_number; hcf > 1; hcf--){
found_hcf = true
for( number of vector){
if( number % hcf != 0 ){
found_hcf = false
break
}
}
if( found_hcf == false)
continue
if( found_hcf == true)
return hcf
}
return 1
}
function get_min_number(vector){
min = 101
for( value of vector){
if( value < min){
min = value
}
}
return min
}
console.log(hcf(numbers))