Skip to content

Instantly share code, notes, and snippets.

@kimhogeling
Created July 11, 2016 08:06
Show Gist options
  • Save kimhogeling/8cba0465a0f1b0060ca31d527753e789 to your computer and use it in GitHub Desktop.
Save kimhogeling/8cba0465a0f1b0060ca31d527753e789 to your computer and use it in GitHub Desktop.
The sandwich functional programming image into code
/**
* 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