Skip to content

Instantly share code, notes, and snippets.

@oampo
Last active June 18, 2017 17:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save oampo/d8b9e6393d94f5e2eeaa944915e9567a to your computer and use it in GitHub Desktop.
Save oampo/d8b9e6393d94f5e2eeaa944915e9567a to your computer and use it in GitHub Desktop.
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