Lately, I’ve been testing my JavaScript knowledge by solving programming problems at Project Euler. While solving the first, quite elementary, practices, it occurred to that some of them can prove useful in real-world applications. So, I decided to extract the useful code from these exercises and release them in nicely packed libraries for use in any JavaScript application.
In this first post in what hopefully will become a series, I release a script to find the least common multiple of a list of numbers. A function to get the least common multiple of a set of numbers is very rudimentary, I know, yet surprisingly lacking from the Math object included in a standard JavaScript installation. I hope that this little pre-made and pre-tested library will save its users the time of writing it themselves.
The small function in this file will add an lcm function to the Math object. You can call the Math.lcm function with one, two or more integers as parameters, and it will return the least common multiple of the given numbers. For example, Math.lcm(3, 4); will return 12, Math.lcm(1, 2, 3, 4, 5, 6); will return 60.

Comments on "JavaScript: finding the least common multiple"
There's one comment to this post. Add yours below.
The trackback URI of this post is http://jw.x10hosting.com/blog/2007/08/22/javascript-finding-the-least-common-multiple/trackback/
JavaScript: Finding primes - JW’s blog wrote:
On November 19th, 2007 at 21:09