Created
February 2, 2021 11:46
-
-
Save bramaudi/c500b9a5390909468d58a6d93eb1728b to your computer and use it in GitHub Desktop.
GCF Ration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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