Skip to content

Instantly share code, notes, and snippets.

@efleming969
Created June 21, 2013 14:28
Show Gist options
  • Select an option

  • Save efleming969/5831540 to your computer and use it in GitHub Desktop.

Select an option

Save efleming969/5831540 to your computer and use it in GitHub Desktop.
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