Skip to content

Instantly share code, notes, and snippets.

@joshuakfarrar
Last active February 24, 2016 00:06
Show Gist options
  • Select an option

  • Save joshuakfarrar/bcea23290e309690857a to your computer and use it in GitHub Desktop.

Select an option

Save joshuakfarrar/bcea23290e309690857a to your computer and use it in GitHub Desktop.
var flags = {
testTransform: (true && true),
another: (true && false)
}
var transforms = {
testTransform: {
apply: flags.testTransform,
function: function(name) { return `${name}!`; }
},
another: {
apply: flags.another,
function: function(name) { return `xXx${name}`; }
},
working: {
apply: true,
function: function(name) { return `${name}?`}
}
};
// any of you code kids: follow along, c'mon. js wit' me now.
var transformed = require('lodash').reduce(transforms, function(result, transform) {
if (transform.apply) {
return (function applyTransformToResult(transform, result) {
return transform(result);
}(transform.function, result));
} else return result;
}, 'joshua');
console.log(transformed); // joshua!?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment