Skip to content

Instantly share code, notes, and snippets.

View niklasramo's full-sized avatar

Niklas Rämö niklasramo

  • Tampere, Finland
View GitHub Profile
const pipe = (...fns) => fns.reduce((f, g) => (...args) => g(f(...args)));
const compose = (...fns) => fns.reduce((f, g) => (...args) => f(g(...args)));
// Example
const addFoo = str => str + 'foo';
const addBar = str => str + 'bar';
const addFoobar = pipe(addFoo, addBar);
const addBarfoo = compose(addFoo, addBar);
addFoobar('hello ') // hello foobar
addBarfoo('hello ') // hello barfoo
@niklasramo
niklasramo / lotto.js
Last active April 22, 2017 21:46
Simple lotto numbers generator
function lotto(amountOfNumbers, from, to) {
const numbers = [];
for (let i = 0; i < amountOfNumbers; i++) {
let number = null;
while (number === null || numbers.indexOf(number) > -1) {
number = Math.floor(Math.random() * (to - from + 1)) + from;
}
numbers.push(number);
}
return numbers.sort((a, b) => a - b);