* feat(interview-prep): Converting and transferring Rosetta problems * feat(interview-prep): Fixing challenges * fix(challenges): Added code tags * Update knight's-tour.md Moved text to instructions section and fixed a small typo. * feat(interview-prep): Update description of Knight's tour Co-Authored-By: NitronR <bhanur05@gmail.com> * feat(interview-prep): Update description of Kaprekar numbers Co-Authored-By: NitronR <bhanur05@gmail.com> * feat(inteview-prep): Kaprekar numbers description Added <code> tags. * fix(interview-prep): Update description Kaprekar Numbers Co-Authored-By: NitronR <bhanur05@gmail.com> * fix(interview-prep): Added code tags Kaprekar numbers Co-Authored-By: NitronR <bhanur05@gmail.com>
		
			
				
	
	
	
		
			2.9 KiB
		
	
	
	
	
	
	
	
			
		
		
	
	
			2.9 KiB
		
	
	
	
	
	
	
	
id, title, challengeType
| id | title | challengeType | 
|---|---|---|
| 5a23c84252665b21eecc7edf | Least common multiple | 5 | 
Description
Instructions
Tests
tests:
  - text: <code>LCM</code> should be a function.
    testString: assert(typeof LCM == 'function', '<code>LCM</code> should be a function.');
  - text: <code>LCM([2, 4, 8])</code> should return a number.
    testString: assert(typeof LCM([2, 4, 8]) == 'number', '<code>LCM([2, 4, 8])</code> should return a number.');
  - text: <code>LCM([2, 4, 8])</code> should return <code>8</code>.
    testString: assert.equal(LCM([2, 4, 8]), 8, '<code>LCM([2, 4, 8])</code> should return <code>8</code>.');
  - text: <code>LCM([4, 8, 12])</code> should return <code>24</code>.
    testString: assert.equal(LCM([4, 8, 12]), 24, '<code>LCM([4, 8, 12])</code> should return <code>24</code>.');
  - text: <code>LCM([3, 4, 5, 12, 40])</code> should return <code>120</code>.
    testString: assert.equal(LCM([3, 4, 5, 12, 40]), 120, '<code>LCM([3, 4, 5, 12, 40])</code> should return <code>120</code>.');
  - text: <code>LCM([11, 33, 90])</code> should return <code>990</code>.
    testString: assert.equal(LCM([11, 33, 90]), 990, '<code>LCM([11, 33, 90])</code> should return <code>990</code>.');
  - text: <code>LCM([-50, 25, -45, -18, 90, 447])</code> should return <code>67050</code>.
    testString: assert.equal(LCM([-50, 25, -45, -18, 90, 447]), 67050, '<code>LCM([-50, 25, -45, -18, 90, 447])</code> should return <code>67050</code>.');
Challenge Seed
function LCM(A) {
  // Good luck!
}
Solution
function LCM (A) {
    var n = A.length, a = Math.abs(A[0]);
    for (var i = 1; i < n; i++)
     { var b = Math.abs(A[i]), c = a;
       while (a && b){ a > b ? a %= b : b %= a; }
       a = Math.abs(c*A[i])/(a+b);
     }
    return a;
}