Last active
June 18, 2017 17:03
-
-
Save oampo/d8b9e6393d94f5e2eeaa944915e9567a 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