Guest User

Untitled

a guest
Jun 21st, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. function smallestCommons(arr) {
  2. arr=arr.sort(function(a,b){
  3. return a>b;
  4. });
  5.  
  6. let myarr=[],newarr;
  7. for(let i=1;i<9999999999;i++){
  8. let num=arr[1]*i;
  9. if(num%arr[0]===0){
  10. for(let j=arr[0]+1;j<arr[1];j++){
  11. if(num%j==0){
  12. myarr.push(j);
  13. }
  14.  
  15. }
  16. if(myarr.length!==arr[1]-arr[0]-1){
  17. myarr.splice(0,myarr.length);
  18. }else{return num;}
  19. }
  20. }
  21. }
  22.  
  23. console.log(smallestCommons([1,5]));
  24.  
  25. function lcm(a, b) {
  26. // First, find the greatest common factor
  27. let gcf = 1;
  28. let r1 = a;
  29. let r2 = b;
  30. while (r1 !== r2) {
  31. let diff = Math.abs(r1 - r2);
  32. r1 = Math.min(r1, r2);
  33. r2 = diff;
  34. }
  35. gcf = r1;
  36.  
  37. // Divide the product of a and b with the GCF:
  38. return (a * b) / gcf;
  39. }
Add Comment
Please, Sign In to add comment