Swapping without taking the remainder makes no progress, so a guard stops it.
Acceptance criteria
- 1.#out should show gcd 6.
Swapping without taking the remainder makes no progress, so a guard stops it.
function gcd(a, b) { let guard = 0; while (b !== 0 && guard < 30) { [a, b] = [b, a]; guard++; } return Math.abs(a); } document.querySelector('#out').textContent = "gcd " + gcd(48, 18);
Output ready when you are
Press Run to render your code, or Submit to validate your solution.