score:1

Accepted answer
const model = (data, predictions, { placeFilter = true, startDateFilter = true, endDateFilter = true }) => {
   const getData = () => data.filter(placeFilter).filter(startDateFilter).filter(endDateFilter)
}

You cannot call the above model function by passing two arguments like model([], []) as JavaScript will try to destructure the third argument which is undefined.

You can do this instead:

const model = (data, predictions, { placeFilter = true, startDateFilter = true, endDateFilter = true } = {}) => {
  console.log(placeFilter, startDateFilter, endDateFilter)
}

model([], [])
model([], [], { placeFilter: false })


BTW Assuming data is an array and you're trying to use Array.prototype.filter, filter should be called with a callback function that returns a boolean but you're directly passing booleans to all filters.

score:0

const model = (data, predictions, { placeFilter = true, startDateFilter = true, endDateFilter = true } = {}) => {
  const getData = () => data.filter(placeFilter).filter(startDateFilter).filter(endDateFilter)
}

score:1

Your parameter could be named to access the default value

const model = (data, predictions, filter = { placeFilter: true, startDateFilter: true, endDateFilter:  true }) => {
   const getData = () => data.filter(filter.placeFilter).filter(filter.startDateFilter).filter(filter.endDateFilter)
}

Related Query

More Query from same tag