File size: 625 Bytes
0936134 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | /* Copyright 2017 Ronny Reichmann */
/* FUZZIFY Adjectify value ranges for later use in pattern matching */
function composeCheckFn (compareFn, adjective) {
return nextCheckFn => {
return value => {
if (compareFn(value)) return adjective
else return nextCheckFn(value)
}
}
}
function fuzzify (config) {
const initializers = Object.keys(config)
.map(adjective => {
const compareFn = config[adjective]
return composeCheckFn(compareFn, adjective)
})
initializers.reverse()
return initializers.reduce((acc, initCheckFn) => initCheckFn(acc), v => v)
}
module.exports = fuzzify
|