File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed
Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change 1+ /*
2+ author: PatOnTheBack
3+ license: GPL-3.0 or later
4+
5+ Modified from:
6+ https://github.com/TheAlgorithms/Python/blob/master/maths/find_lcm.py
7+
8+ More about LCM:
9+ https://en.wikipedia.org/wiki/Least_common_multiple
10+ */
11+
12+ // Find the LCM of two numbers.
13+ function find_lcm ( num_1 , num_2 ) {
14+ "use strict" ;
15+ var max_num ,
16+ lcm ;
17+ // Check to see whether num_1 or num_2 is larger.
18+ if ( num_1 > num_2 ) {
19+ max_num = num_1 ;
20+ } else {
21+ max_num = num_2 ;
22+ }
23+ lcm = max_num ;
24+
25+ while ( true ) {
26+ if ( ( lcm % num_1 === 0 ) && ( lcm % num_2 === 0 ) ) {
27+ break ;
28+ }
29+ lcm += max_num ;
30+ }
31+ return lcm ;
32+ }
33+
34+ // Run `find_lcm` Function
35+ var num_1 = 12 ,
36+ num_2 = 76 ;
37+ console . log ( find_lcm ( num_1 , num_2 ) ) ;
You can’t perform that action at this time.
0 commit comments