Last active
December 24, 2015 08:18
-
-
Save matsko/6769304 to your computer and use it in GitHub Desktop.
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
function filter(exp) { | |
return function filterHandler(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 evenNumbersFilterExpression(value) { | |
return value % 2 == 0; | |
}); | |
var stringsLessThan5 = filter(function stringsLessThan5FilterExpression(value) { | |
return value.length < 5; | |
}); | |
console.log(evenNumbers([1,2,3,4,5])); | |
> jscheckstyle app.js 16:00:37 | |
jscheckstyle results - app.js | |
┌────────┬────────────────────────────────────────┬────────┬──────┬──────────┐ | |
│ Line │ Function │ Length │ Args │ Complex… │ | |
├────────┼────────────────────────────────────────┼────────┼──────┼──────────┤ | |
│ 1 │ filter │ 12 │ 1 │ 4 │ | |
├────────┼────────────────────────────────────────┼────────┼──────┼──────────┤ | |
│ 2 │ filterHandler │ 10 │ 1 │ 3 │ | |
├────────┼────────────────────────────────────────┼────────┼──────┼──────────┤ | |
│ 14 │ evenNumbersFilterExpression │ 3 │ 1 │ 2 │ | |
├────────┼────────────────────────────────────────┼────────┼──────┼──────────┤ | |
│ 18 │ stringsLessThan5FilterExpression │ 3 │ 1 │ 2 │ | |
└────────┴────────────────────────────────────────┴────────┴──────┴──────────┘ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment