Last active
August 2, 2016 21:19
-
-
Save ivanoats/8734fc314e4d3c9ef718d743b2c5a238 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env babel-node | |
import _ from 'lodash/fp' | |
const filters = { | |
// cities | |
sea: true, | |
nyc: false, | |
// experience levels | |
beginner: true, | |
intermediate: true, | |
advanced: false, | |
// formats | |
workshop: true, | |
part: true, | |
full: false, | |
} | |
const courseListings = [ | |
{ cityCode: 'sea', name: '101', exp: 'beginner', format: 'workshop' }, | |
{ cityCode: 'sea', name: '201', exp: 'advanced', format: 'part' }, | |
{ cityCode: 'nyc', name: '102', exp: 'intermediate', format: 'workshop' }, | |
] | |
const pickTrue = _.pickBy((f) => f) | |
const trueFilters = Object.keys(pickTrue(filters)) | |
const filterCourses = (attribute) => _.includes(attribute, trueFilters) | |
const byCity = (c) => filterCourses(c.cityCode) | |
const byExp = (c) => filterCourses(c.exp) | |
const byFormat = (c) => filterCourses(c.format) | |
const filteredCourses = _.intersection( | |
courseListings.filter(byExp), | |
courseListings.filter(byCity), | |
courseListings.filter(byFormat) | |
) | |
console.log(filteredCourses) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment