Skip to content

Instantly share code, notes, and snippets.

@bramaudi
Created February 2, 2021 11:46
Show Gist options
  • Select an option

  • Save bramaudi/c500b9a5390909468d58a6d93eb1728b to your computer and use it in GitHub Desktop.

Select an option

Save bramaudi/c500b9a5390909468d58a6d93eb1728b to your computer and use it in GitHub Desktop.
GCF Ration
// Greatest Common Factor with Euclidean Algorithm
const GCF = (a, b) => {
if (b === 0) return a
else return GCF(b, a % b)
}
// Divide each number by GCF
const ratio = (a, b) => {
const c = GCF(a, b)
a = a / c
b = b / c
return `${a}:${b}`
}
const width = 1280
const height = 720
// GCF
console.log(GCF(width, height)) // 80
// Ratio
console.log(ratio(width, height)) // 16:9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment