Skip to content

Instantly share code, notes, and snippets.

@bhalash
Last active August 26, 2016 20:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bhalash/612f57ff222a920bf5e2a7f3b3e0e514 to your computer and use it in GitHub Desktop.
Save bhalash/612f57ff222a920bf5e2a7f3b3e0e514 to your computer and use it in GitHub Desktop.
Doublers
var doublers = [
n => n * 2,
n => n + n,
n => n << 1
];
var double = n => _.sample(doublers)(n),
verifyDoubling = (n, x) => n * 2 === x;
var a = [];
a = _.times(100, i => verifyDoubling(i, double(i)));
a = _.reduce(a, (last, n) => n && n === last, true);
console.log(a);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment