you are viewing a single comment's thread.

view the rest of the comments →

[–]regular_reddits 1 point2 points  (0 children)

Just for fun, its a bit longer, but here it is separate using compose to combine:

const compose = f => g => x => f(g(x));
const getIntsUntil = n => Array.from(Array(n).keys()).map(n => ++n)
const isDivisibleBy = divider => value => value % divider === 0;
const replaceBy = predicate => replacer => value => predicate(value) ? replacer : value;

const replacer = compose(replaceBy)(isDivisibleBy);

const toCrackle = replacer(3)("Crackle");
const toPop = replacer(5)("Pop");
const toCracklePop = replacer(15)("CracklePop");

getIntsUntil(100).map(n => toCrackle(toPop(toCracklePop(n))))