Skip to content

Instantly share code, notes, and snippets.

@ivanoats
Last active August 2, 2016 21:19
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 ivanoats/8734fc314e4d3c9ef718d743b2c5a238 to your computer and use it in GitHub Desktop.
Save ivanoats/8734fc314e4d3c9ef718d743b2c5a238 to your computer and use it in GitHub Desktop.
#!/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