← Back to challenges

Least Common Multiple

JavaScriptHardmathnumbersarrays

Instructions

Given an array of integers, create a function that will find the smallest positive integer that is evenly divisible by all the members of the array. In other words, find the least common multiple (LCM).

Examples

lcm([1, 2, 3, 4, 5, 6, 7, 8, 9]) ➞ 2520

lcm([5]) ➞ 5

lcm([5, 7, 11]) ➞ 385

lcm([5, 7, 11, 35, 55, 77]) ➞ 385

Notes

N/A

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.