**I am practicing writing code in a functional style, but it turns out badly, please help me rewrite this task**

Alice and Bob take turns playing a game, with Alice starting first.

There are `n`

stones in a pile. On each player’s turn, they can **remove** a stone from the pile and receive points based on the stone’s value. Alice and Bob may **value the stones differently** .

You are given two integer arrays of length `n`

, `aliceValues`

and `bobValues`

. Each `aliceValues[i]`

and `bobValues[i]`

represents how Alice and Bob, respectively, value the `ith`

stone.

The winner is the person with the most points after all the stones are chosen. If both players have the same amount of points, the game results in a draw. Both players will play **optimally** . Both players know the other’s values.

Determine the result of the game, and:

- If Alice wins, return
`1`

. - If Bob wins, return
`-1`

. - If the game results in a draw, return
`0`

.

**Example :**

**Input:** aliceValues = [1,3], bobValues = [2,1] **Output:** 1 **Explanation:** If Alice takes stone 1 (0-indexed) first, Alice will receive 3 points. Bob can only choose stone 0, and will only receive 2 points. Alice wins.

```
let stoneGameVI = function (aliceValues, bobValues) {
let winAlice = 0;
let winBob = 0;
let arr = [];
for (let i = 0; i < aliceValues.length; i++) {
arr.push([aliceValues[i] + bobValues[i], aliceValues[i], bobValues[i]]);
}
arr.sort((a, b) => b[0] - a[0]);
for (let i = 0; i < aliceValues.length; i += 2) {
winAlice += arr[i][1]
if (arr[i + 1] !== undefined) {
winBob += arr[i + 1][2]
}
}
if (winAlice > winBob) return 1
if (winAlice === winBob) return 0
if (winAlice < winBob) return -1
};
```