Skip to content

Instantly share code, notes, and snippets.

@hughfdjackson
Created January 26, 2013 23:18
Show Gist options
  • Select an option

  • Save hughfdjackson/4645252 to your computer and use it in GitHub Desktop.

Select an option

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