v0 Jun 2018
You are allowed to use, modify or distribute this piece of code as pleased. The author cannot be made responsible for anything that could derive from the use or misuse of this software.
f = ( // Given | |
n, // A number greater than 0 (limited by the call stack size cap) | |
a, // An optional numerator | |
b // And an optional denominator | |
) => | |
[ // Have a collection of functions that | |
_ => f(n, a + 1, b), // - Adds one to the numerator if the fraction is smaller than the number | |
_ => `${a}/${b}`, // - Returns a string of the resulting fraction if it's equal to the number | |
_ => f(n, a, b + 1), // - Adds one to the denominator if the fraction is larger than the number | |
][ // And return the value of one based on |