Last active
November 4, 2018 15:59
-
-
Save Expl4Life/0948b88e6244c7cbce9a4e614b64bfaf to your computer and use it in GitHub Desktop.
findEqualSquareAreaSection
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
//"разделяй и влавствуй" | |
function findEqualSquareAreaSection(width = 0, height = 0) { | |
if(isNaN(width) || isNaN(height) || height < 0 || width < 0) { | |
return null; | |
} | |
const bigSide = Math.max(width, height); | |
const smallSide = Math.min(width, height); | |
if(bigSide % smallSide === 0) { | |
return smallSide; | |
} | |
return findEqualSquareAreaSection(smallSide, (bigSide - smallSide)); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment