Created
October 19, 2016 14:03
-
-
Save abuseofnotation/a0bfc6a244c1ae47248dd50b976d638c 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
//Converts a value to string | |
const valueAsString = (value) => value.toString() | |
//Returns true if 'num' is divided without remainder by 'divider' | |
const dividesBy = (divider) => (num) => num % divider === 0 | |
//Prints 'i' only if it obeys the condition given by 'cond', using 'f' as a formatting function | |
const printIf = (cond, f) => (i) => cond(i) ? f(i) : "" | |
//Applies an array of functions to a value and concats the result | |
const applyOnAll = (functions, value) => functions.map((f)=> f(value)) | |
//Applies several 'functions' to 'i' and concats the results. | |
const concat = (...functions) => (value) => applyOnAll(functions, value).join('') | |
//Applies several functions to a value and returns true if some of them return true | |
const not = (...functions) => (value) => !_.find(applyOnAll(functions, value)) | |
//The solution itself. No need for description here. | |
console.log(_.range(1,100).map(concat( | |
printIf(dividesBy(3), _.constant("fizz")), | |
printIf(dividesBy(5), _.constant("buzz")), | |
printIf(not(dividesBy(5), dividesBy(3)), valueAsString) | |
)).join('\n')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment