Skip to content

Instantly share code, notes, and snippets.

@matsko
Created September 29, 2013 22:42
Show Gist options
  • Save matsko/6757246 to your computer and use it in GitHub Desktop.
Save matsko/6757246 to your computer and use it in GitHub Desktop.
//
// PROGRAM
//
function filter(exp) {
return function(array) {
var newArray = [];
for(var i=0;i<array.length;i++) {
var a = array[i];
if(exp(a)) {
newArray.push(a);
}
}
return newArray;
}
};
var evenNumbers = filter(function(value) {
return value % 2 == 0;
});
var stringsLessThan5 = filter(function(value) {
return value.length < 5;
});
console.log(evenNumbers([1,2,3,4,5]));
//
// RESULTS
//
> jscheckstyle app.js 13:53:16
jscheckstyle results - app.js
┌────────┬────────────────────────────────────────┬────────┬──────┬──────────┐
│ Line │ Function │ Length │ Args │ Complex… │
├────────┼────────────────────────────────────────┼────────┼──────┼──────────┤
│ 1 │ filter │ 12 │ 1 │ 4 │
├────────┼────────────────────────────────────────┼────────┼──────┼──────────┤
│ 2 │ anonymous │ 10 │ 1 │ 3 │
├────────┼────────────────────────────────────────┼────────┼──────┼──────────┤
│ 14 │ anonymous │ 3 │ 1 │ 2 │
├────────┼────────────────────────────────────────┼────────┼──────┼──────────┤
│ 18 │ anonymous │ 3 │ 1 │ 2 │
└────────┴────────────────────────────────────────┴────────┴──────┴──────────┘
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment