Skip to content

Instantly share code, notes, and snippets.

@gmilby
Forked from zonpantli/gist:907577
Created May 20, 2013 18:38
Show Gist options
  • Save gmilby/5614282 to your computer and use it in GitHub Desktop.
Save gmilby/5614282 to your computer and use it in GitHub Desktop.
// from http://kriszyp.name/2010/01/16/imperative-functional-and-declarative-programming/
// imperative
function bestPrices(inputArray){
var outputArray = [];
for(var i = 0; i < inputArray.length; i++){
if(inputArray[i].price<10){
outputArray.push(inputArray[i]);
}
}
return outputArray;
}
//functional
function bestPrices(inputArray){
return Array.filter(inputArray, function(value){
return value.price < 10;
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment