Scrubbed Inputs
by in CodeSOD on 2016-03-30In this age of JavaScript everywhere, developers have to come up with all sorts of ways to work around the uglier segments of JavaScript. For example, Aaron found this block, which promises to scrub “false-y” fields.
require _ = require("underscore");
// recurses, use with care
var scrubFalseyFields = function (obj) {
return _.chain(obj)
.pairs()
.filter(function (pair) {
var val = pair[1];
if (_.isObject(pair[1])) {
// recurse!
pair[1] = scrubFalseyFields(val);
}
return val;
})
.object()
.value();
};