Created
November 11, 2018 08:57
-
-
Save chadfurman/b34d48d486a0d9706566c40820c1fbf6 to your computer and use it in GitHub Desktop.
horr
This file contains 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
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