Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jackbillstrom/809ad8c2ee54c103f45ed4cf1f54d755 to your computer and use it in GitHub Desktop.
Save jackbillstrom/809ad8c2ee54c103f45ed4cf1f54d755 to your computer and use it in GitHub Desktop.
filtered_boats: function () {
let filtered = this.boats;
// the minimums
let mins = {
"minPrice": 'price',
"minLength": 'length',
...
};
filtered = Object.keys(mins).forEach(k => if (this.filter.options[k] !== null) filtered = filtered.filter(boat => boat[mins[k]] >= this.filter.options[k]));
// the maximums
let maxs = {
"maxPrice": 'price',
"maxLength": 'length',
...
};
filtered = Object.keys(maxs).forEach(k => if (this.filter.options[k] !== null) filtered = filtered.filter(boat => boat[maxs[k]] <= this.filter.options[k]));
// the multi-value filters
let fields = ['brand', 'model', 'type', ...];
filtered = fields.forEach(f => if (this.filter.options[f].length > 0) filtered = filtered.filter(boat => this.filter.options[f].indexOf(boat[f]) != -1));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment