Created
December 25, 2011 15:48
-
-
Save sri-rang/1519447 to your computer and use it in GitHub Desktop.
Functional Programming in JavaScript - 4
This file contains 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
var forEach = function (list, action) { | |
for (var i = 0; i < list.length; i++) { | |
action(list[i]); | |
} | |
}; | |
var logItem = function (item) { | |
console.log(item); | |
}; | |
var listOfThings = ["soap", "candle", "deer", "wine", "bread"]; | |
var anotherListOfThings = ["grapes", "apples", "beer", "pizza"]; | |
forEach(listOfThings, logItem); | |
forEach(anotherListOfThings, function (item) { | |
console.log(item + "'s length is " + item.length); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
//Great read so far.
//If you would like correct grammar replace the final forEach with:
forEach(anotherListOfThings, function (item) {
if(item[item.length-1]==="s"){
console.log(item + "' length is " + item.length);
}else{
console.log(item + "'s length is " + item.length);
}
});