---
id: 6a26df3e2988bcdded204895
title: "Challenge 359: Golf Handicap Calculator"
challengeType: 28
dashedName: challenge-359
---

# --description--

Given an array of golf scores and a corresponding array of course par values, return the golfer's handicap index using the following method:

- Calculate the differential for each round by subtracting the par from the score, then return the average of all differentials rounded to one decimal place.

# --hints--

`calculateHandicap([72, 72, 72], [72, 72, 72])` should return `0`.

```js
assert.equal(calculateHandicap([72, 72, 72], [72, 72, 72]), 0);
```

`calculateHandicap([80, 76, 78, 78], [72, 72, 72, 72])` should return `6`.

```js
assert.equal(calculateHandicap([80, 76, 78, 78], [72, 72, 72, 72]), 6);
```

`calculateHandicap([42, 45, 46, 44], [36, 36, 36, 36])` should return `8.3`.

```js
assert.equal(calculateHandicap([42, 45, 46, 44], [36, 36, 36, 36]), 8.3);
```

`calculateHandicap([85, 80, 76, 79, 82], [72, 72, 72, 71, 71])` should return `8.8`.

```js
assert.equal(calculateHandicap([85, 80, 76, 79, 82], [72, 72, 72, 71, 71]), 8.8);
```

`calculateHandicap([41, 50, 48, 52, 46, 49], [35, 37, 35, 37, 35, 37])` should return `11.7`.

```js
assert.equal(calculateHandicap([41, 50, 48, 52, 46, 49], [35, 37, 35, 37, 35, 37]), 11.7);
```

# --seed--

## --seed-contents--

```js
function calculateHandicap(scores, pars) {

  return scores;
}
```

# --solutions--

```js
function calculateHandicap(scores, pars) {
  const differentials = scores.map((score, i) => score - pars[i]);
  const average = differentials.reduce((sum, d) => sum + d, 0) / differentials.length;
  return Math.round(average * 10) / 10;
}
```
