Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                
              
            
!

CSS

              
                
              
            
!

JS

              
                /* to find LCM for more than 2 numbers, have to use prime factorization method
   
   18          19            20          21           22          23
   2, 3, 3     1, 19         2, 2, 5     3, 7         2, 11       1, 23
      ^  ^        ^          ^  ^  ^        ^            ^           ^
      
      3 * 3     * 19       * 2 * 2 * 5    * 7          * 11        * 23 = 6056820
      
*/

function getPrimes(number) {
   var i = 2,
       primes = [];

   while (i <= number) {
      if (number % i === 0) {
         primes.push(i);
         number /= i;
      } else {
         i += 1;
      }
   }

   return primes;
}


// find smallest common multiple
function smallestCommons(arr) {

   // sort input array low to high
   arr = arr.sort((a, b) => a - b);

   // setup
   var series = [],
       primesArr;

   // generate number series, inclusive of start & finish
   for (var i = arr[0]; i <= arr[1]; i += 1) {
      series.push(i);
   }

   // build prime factors array
   primesArr = series.map(function(num) {
      return getPrimes(num);
   });

   // log primes array
   console.log('\nInput series : ' + series + '\nPrime Factors: ', primesArr);

   //
   // NOT CORRECT
   return primesArr
      .reduce(function(a, b) {
         return a.concat(b);
      })
      .reduce(function(acc, val) {
         return acc * val;
      });

}

// TESTS

console.log(
   smallestCommons([1, 5])
   // should return 60
);
console.log(
   smallestCommons([5, 1])
   // should return 60  
);
console.log(
   smallestCommons([1, 13])
   // should return 360360.
);
console.log(
   smallestCommons([23, 18])
   // should return 6056820
);
              
            
!
999px

Console