.DS_Store
# reduce-data-with-javascript
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Plunker</title>
</head>
<body>
<script>
// Allows Plunker to display logs in preview panel
// for better in-browser experience
var originalConsoleLog = console.log
console.log = function () {
originalConsoleLog.apply(console, arguments)
var args = Array.prototype.slice.call(arguments);
document.body.innerText += args.join(' ') + '\n';
document.body.style['fontFamily'] = 'monospace';
document.body.style['fontSize'] = '1.5em';
};
</script>
<script src="script.js"></script>
</body>
</html>
function increment(input) { return input + 1;}
function decrement(input) { return input - 1; }
function double(input) { return input * 2; }
function halve(input) { return input / 2; }
var initial_value = 1;
var pipeline = [
increment,
increment,
increment,
double,
increment,
increment,
halve
];
var final_value = pipeline.reduce(function(acc, fn) {
return fn(acc);
}, initial_value);
var reversed = pipeline.reduceRight(function(acc, fn) {
return fn(acc);
}, initial_value)
console.log("final_value: ", final_value)
console.log("reversed: ", reversed)