Commit 6722d5e0408124332904314dfb6c84ed5e98b49c
Use some destructuring and const
Piet Geursen committed on 3/7/2018, 1:04:57 AMParent: 97bde7ce4cb8f440a82828ea953f2e6f63c7e20e
Files changed
position/sync/chooseOneResults.js | changed |
position/sync/chooseOneResults.js | ||
---|---|---|
@@ -1,6 +1,6 @@ | ||
1 | -var isArray = require('isarray') | |
2 | -var Position = require('../../position/sync/position') | |
1 | +const isArray = require('isarray') | |
2 | +const Position = require('../../position/sync/position') | |
3 | 3 | |
4 | 4 | // Expects `poll` and `position` objects passed in to be of shape: |
5 | 5 | // { |
6 | 6 | // value: { |
@@ -12,9 +12,10 @@ | ||
12 | 12 | // |
13 | 13 | // postions must be of the correct type ie: type checked by the caller. |
14 | 14 | module.exports = function ({positions, poll}) { |
15 | 15 | return positions.reduce(function (results, position) { |
16 | - var { positionDetails: {choice} } = Position(position) | |
16 | + const { value: {author}} = position | |
17 | + const { positionDetails: {choice} } = Position(position) | |
17 | 18 | |
18 | 19 | if (isInvalidChoice({position, poll}) || isPositionAfterClose({position, poll})) { |
19 | 20 | results.errors.invalidPositions.push(position) |
20 | 21 | return results |
@@ -22,16 +23,16 @@ | ||
22 | 23 | |
23 | 24 | if (!isArray(results[choice])) { |
24 | 25 | results[choice] = [] |
25 | 26 | } |
26 | - results[choice].push(position.value.author) | |
27 | + results[choice].push(author) | |
27 | 28 | |
28 | 29 | return results |
29 | 30 | }, {errors: {invalidPositions: []}}) |
30 | 31 | } |
31 | 32 | |
32 | 33 | function isInvalidChoice ({position, poll}) { |
33 | - var { positionDetails: {choice} } = Position(position) | |
34 | + const { positionDetails: {choice} } = Position(position) | |
34 | 35 | return choice >= poll.pollDetails.choices.length |
35 | 36 | } |
36 | 37 | |
37 | 38 | function isPositionAfterClose ({position, poll}) { |
Built with git-ssb-web