Created
June 21, 2013 14:28
-
-
Save efleming969/5831540 to your computer and use it in GitHub Desktop.
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
| function countIf(listOfNames, condition) { | |
| var i, name, count = 0; | |
| for(i = 0; i < listOfNames.length; i++) { | |
| name = listOfNames[i]; | |
| if (condition(name)) { | |
| count = count + 1; | |
| } | |
| } | |
| return count; | |
| } | |
| var myNames = ["erick", "nicole", "niko", "zola"]; | |
| function hasLengthGreaterThan(someLength) { | |
| return function (x) { | |
| return (x.length > someLength) | |
| } | |
| } | |
| var r1 = countIf(myNames, hasLengthGreaterThan(4)) | |
| console.log(r1) | |
| function startsWith(someLetter) { | |
| return function (x) { | |
| return (x.indexOf(someLetter) == 0) | |
| } | |
| } | |
| var startsWithN = startsWith("n") | |
| var startsWithS = startsWith("s") | |
| var startsWithE = startsWith("e") | |
| var r2 = countIf(myNames, startsWithN) | |
| console.log(r2) | |
| function compose(f, g) { | |
| return function (x) { | |
| return f(g(x)) | |
| } | |
| } | |
| var exp_sin = compose(Math.sin, Math.exp) | |
| console.log(exp_sin(3)) | |
| var startsWithNandIsGreaterThan4 = compose(startsWith("n"), hasLengthGreaterThan(4)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment