Created
January 23, 2017 21:05
-
-
Save sghall/634c1099e731542a0a076286f052eedc to your computer and use it in GitHub Desktop.
Min Perimeter for Rectangle of Given Area in JavaScript
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 minPerimeter(num) { | |
let min = 0; | |
for (let i = 0; i * i <= num; i++) { | |
if (num % i === 0) { | |
min = 2 * (i + (num / i)); | |
if (!(i === num / i)) { | |
if (min > 2 * (i + (num / i))) { | |
min = 2 * (i + (num / i)); | |
} | |
} | |
} | |
} | |
return min; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment