Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function smallestCommons(arr) {
- arr=arr.sort(function(a,b){
- return a>b;
- });
- let myarr=[],newarr;
- for(let i=1;i<9999999999;i++){
- let num=arr[1]*i;
- if(num%arr[0]===0){
- for(let j=arr[0]+1;j<arr[1];j++){
- if(num%j==0){
- myarr.push(j);
- }
- }
- if(myarr.length!==arr[1]-arr[0]-1){
- myarr.splice(0,myarr.length);
- }else{return num;}
- }
- }
- }
- console.log(smallestCommons([1,5]));
- function lcm(a, b) {
- // First, find the greatest common factor
- let gcf = 1;
- let r1 = a;
- let r2 = b;
- while (r1 !== r2) {
- let diff = Math.abs(r1 - r2);
- r1 = Math.min(r1, r2);
- r2 = diff;
- }
- gcf = r1;
- // Divide the product of a and b with the GCF:
- return (a * b) / gcf;
- }
Add Comment
Please, Sign In to add comment