Published
Edited
Feb 4, 2021
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
gcd = function(a,b){
let r = [a,b] // Start with [a,b]
let i = 0 // Track where we are in the array
while(r[i]!==r[i+1]){ // While the two values near the tracker are not equal...
r.push(Math.abs(r[i]-r[i+1])) // Add (a-b) to the array
i++ // Move the tracker one space forward
} // Once we find two equal values in a row...
return r[i] // Output the GCD
}
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more