Last active
April 12, 2018 08:47
-
-
Save joe-crick/e39f1b21fcbbdaa597d82e5ca10f6a2d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
methods: { | |
getSmallestBidFromRange() { | |
const start = parseInt(this.start); | |
const end = parseInt(this.end); | |
this.smallestValue = this.items | |
.filter(bidsInRange(start, end)) | |
.reduce((cur, prev) => { | |
if (prev) { | |
return cur; | |
} else { | |
return cur.bid < prev.bid ? cur : prev; | |
} | |
}).bid; | |
}, | |
getSumFromRange() { | |
const start = parseInt(this.start); | |
const end = parseInt(this.end); | |
this.sum = this.items | |
.filter(bidsInRange(start, end)) | |
.reduce( | |
(prev, cur) => { | |
prev.bid += cur.bid; | |
return prev; | |
}, | |
{ bid: 0 } | |
) | |
.bid.toFixed(2); | |
} | |
// ... Rest of object code | |
// Filter function for finding bids in a range | |
function bidsInRange(start, end) { | |
return bid => bid.index >= start && bid.index <= end; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment