File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed
Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change 1+ // Find the smallest common multiple of the given parameters that can be evenly divided by both, as well as
2+ // by all numbers in the range between these parameters.
3+ // The range is an array of two numbers, not necessarily be in numerical order.
4+
5+ function smallestCommons ( arr ) {
6+ arr . sort ( function ( a , b ) { //sorting given numbers
7+ return b - a ;
8+ } ) ;
9+
10+ var num = [ ] ;
11+ for ( var i = arr [ 0 ] ; i >= arr [ 1 ] ; i -- ) { //create array of all nums
12+ num . push ( i ) ;
13+ }
14+
15+ var quot = 0 ; //variables for the quotient that can access them outside the loop
16+ var loop = 1 ;
17+ var n ;
18+ // Run code while n is not the same as the array length.
19+ do {
20+ quot = num [ 0 ] * loop * num [ 1 ] ;
21+ for ( n = 2 ; n < num . length ; n ++ ) {
22+ if ( quot % num [ n ] !== 0 ) {
23+ break ;
24+ }
25+ }
26+ loop ++ ;
27+ } while ( n !== num . length ) ;
28+
29+ return quot ;
30+ }
31+
32+ smallestCommons ( [ 1 , 5 ] ) ;
You can’t perform that action at this time.
0 commit comments