Created
January 26, 2013 23:18
-
-
Save hughfdjackson/4645252 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
| // creating a new function without members that fail a truth step | |
| var arr = [0, 1, 2, 3] | |
| // imperative | |
| var arrIm = [], | |
| isEven = function(a){ return a % 2 === 0 } | |
| for ( var i = 0; i < arr.length; i += 1 ) { | |
| if ( isEven(arr[i]) ) arrIm.push(arr[i]) | |
| } | |
| // functional | |
| var arrFp = arr.filter(isEven) |
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
| // creating a new function with new values. | |
| var arr = [0, 1, 2, 3] | |
| // imperative | |
| var arrIm = [] | |
| for ( var i = 0; i < arr.length; i += 1 ) { | |
| arrIm.push(arr[i] + 1) | |
| } | |
| // functional | |
| var inc = function(a){ return a + 1 }, | |
| arrFp = arr.map(inc) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment