# Codility: MinAvgTwoSlice Solution

*Lesson 5 Prefix Sums*

1function solution(A) {2 let min = (minI = Infinity)3 for (let i = 0; i < A.length - 1; i++) {4 const avg = (A[i] + A[i + 1]) / 25 if (avg < min) {6 min = avg7 minI = i8 }9 }10 for (let i = 0; i < A.length - 2; i++) {11 const avg = (A[i] + A[i + 1] + A[i + 2]) / 312 if (avg < min) {13 min = avg14 minI = i15 }16 }17 return minI18}

## 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.