Skip to content

Instantly share code, notes, and snippets.

@chadfurman
Created November 11, 2018 08:57
Show Gist options
  • Save chadfurman/b34d48d486a0d9706566c40820c1fbf6 to your computer and use it in GitHub Desktop.
Save chadfurman/b34d48d486a0d9706566c40820c1fbf6 to your computer and use it in GitHub Desktop.
horr
function filterMails(mails, stat) {
let matchingPredicate = _.filter(mails, (mail) => {
let test = mail.predicate.split(' ')
stat.cases = _.map(test, (filter) => {
let operation = filter.split(/([=<>]{1,2})/g)
if (operation.length && operation.length === 3) {
let mainNum
let comparator
if (operation[0] === 'lastEntry') {
// TODO: parse dates
} else {
mainNum = parseInt(stat[operation[0]], 10)
comparator = parseInt(operation[2], 10)
}
switch (operation[1]) {
case '<':
return mainNum < comparator
case '>':
return mainNum > comparator
case '=':
return mainNum === comparator
case '<=':
return mainNum <= comparator
case '>=':
return mainNum >= comparator
default:
return false
}
}
return operation
})
return _.every(stat.cases, Boolean)
})
return matchingPredicate
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment