Skip to content

Instantly share code, notes, and snippets.

@Expl4Life
Last active November 4, 2018 15:59
Show Gist options
  • Save Expl4Life/0948b88e6244c7cbce9a4e614b64bfaf to your computer and use it in GitHub Desktop.
Save Expl4Life/0948b88e6244c7cbce9a4e614b64bfaf to your computer and use it in GitHub Desktop.
findEqualSquareAreaSection
//"разделяй и влавствуй"
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