Skip to content

Instantly share code, notes, and snippets.

@nicohvi
Last active August 29, 2015 14:05
Show Gist options
  • Save nicohvi/fe856380c847283c5297 to your computer and use it in GitHub Desktop.
Save nicohvi/fe856380c847283c5297 to your computer and use it in GitHub Desktop.
Functional programming
function whosTopDog(dogs, comparison) {
for (var i=0; i < dogs.length; i++) comparison(dogs[i]);
}
whosTopDog(['ice cube', '50 cent', 'snoop'], function(dog) {
if(dog === 'snoop dog') {
console.log(dog+ ' is top deg.');
}
else {
console.log(dog+ ' is a bitch.');
}
});
array = ['ice cube', '50 cent', 'snoop']
map(array, function(value, index) {
return value+ ' has index: ' +index+ ' in the array.';
})
var map = function(items, fn) {
var newArray = [];
for(var i=0; i < items.length; i++) newArray.push(fn(items[i], i));
return newArray;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment