Skip to content

Instantly share code, notes, and snippets.

@sghall
Created January 23, 2017 21:05
Show Gist options
  • Save sghall/634c1099e731542a0a076286f052eedc to your computer and use it in GitHub Desktop.
Save sghall/634c1099e731542a0a076286f052eedc to your computer and use it in GitHub Desktop.
Min Perimeter for Rectangle of Given Area in JavaScript
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