# Codility: MinPerimeterRectangle Solution

*Lesson 10 Prime and Composite Numbers*

1function solution(N) {2 function perimeter(a, b) {3 return 2 * (a + b)4 }56 let min = Infinity7 let i = 18 while (i * i < N) {9 if (N % i === 0) {10 min = Math.min(min, perimeter(i, N / i))11 }12 i++13 }14 if (i * i === N) {15 min = Math.min(min, 4 * i)16 }1718 return min19}

## Comments

Loading comments...

## Tags

codility

## Apply and earn a $2,500 bonus once you're hired on your first job!

Clients from the Fortune 500 to Silicon Valley startups

Choose your own rate, get paid on time

From hourly, part-time, to full-time positions

Flexible remote working environment

A lot of open JavaScript jobs!!

**Fact corner:** Referred talent are 5x more likely to pass the Toptal screening process than the average applicant.

**Still hesitate?** Read HoningJS author's guide on dealing with Toptal interview process.