Created
July 11, 2016 08:06
-
-
Save kimhogeling/8cba0465a0f1b0060ca31d527753e789 to your computer and use it in GitHub Desktop.
The sandwich functional programming image into code
This file contains hidden or 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
/** | |
* Work in progress.. does not work yet | |
*/ | |
var recipe = [ | |
{ name: 'bread', slices: 2 }, | |
{ name: 'cucumber', slices: 6 }, | |
{ name: 'paprika', slices: 8 }, | |
{ name: 'tomato', slices: 5 }, | |
{ name: 'salad', slices: 15 }, | |
{ name: 'onion', slices: 20 } | |
] | |
var slice = ({ name, slices }) => { | |
let i, createdSlices = [] | |
for (i = 0; i < slices; i++) { | |
createdSlices.push(name + ' slice') | |
} | |
return createdSlices | |
} | |
var mix = (finished, slices) => { | |
var i, amount = 3 | |
finishes = finished || {} | |
for (i = 0; i < amount; i++) { | |
finished['Sandwich ' + amount] = finished['Sandwich ' + amount] || {} | |
finished['Sandwich ' + amount][slices[0]] = slices.reduce(s => { | |
return s | |
}) | |
} | |
return finished | |
} | |
recipe.map(slice).reduce(mix) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment