Skip to content

Instantly share code, notes, and snippets.

@joe-crick
Last active April 12, 2018 08:47
Show Gist options
  • Save joe-crick/e39f1b21fcbbdaa597d82e5ca10f6a2d to your computer and use it in GitHub Desktop.
Save joe-crick/e39f1b21fcbbdaa597d82e5ca10f6a2d to your computer and use it in GitHub Desktop.
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