Forked from oampo/higher-order-function-drill-solutions.js
Created
June 18, 2017 17:03
-
-
Save SecureCloud-biz/cf68800a4544d4358b204675dd01fe45 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
function repeat(fn, n) { | |
for (var i=0; i<n; i++) { | |
fn(); | |
} | |
}; | |
function sayHello() { | |
console.log('Hello'); | |
} | |
repeat(sayHello, 10); | |
function createGreeter(greeting) { | |
return function(name) { | |
console.log(greeting, name); | |
}; | |
} | |
var hello = createGreeter('Hello'); | |
var bonjour = createGreeter('Bonjour'); | |
var hej = createGreeter('Hej'); | |
hello('Joe'); | |
bonjour('Joe'); | |
hej('Joe'); | |
var movements = [[0, 0], [0, 5], [-1, -3], [-3, 1], [2, -4], [3, 2]]; | |
movements = movements.filter(function(movement) { | |
return movement[0] >= 0 && movement[1] >= 0; | |
}); | |
distances = movements.map(function(movement) { | |
return movement[0] + movement[1]; | |
}); | |
distances.forEach(function(distance) { | |
console.log(distance); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment