Write a function that returns the least common multiple (LCM) of two integers.

Examples

 lcm(9, 18) ➞ 18  lcm(8, 5) ➞ 40  lcm(17, 11) ➞ 187 

Notes

  • Both values will be positive.
  • The LCM is the smallest integer that is divisible by both numbers such that the remainder is zero.

Solution:

 1  2  3  4  5  6  7  8  9 10
function lcm(n1, n2) { 	let max = Math.max(n1,n2); 	while(true){ 		if(max%n1 == 0 && max%n2 ==0){ 			return max; 		}else{ 			max++; 		} 	} } 

This free site is ad-supported. Learn more