Last active
January 26, 2020 13:19
-
-
Save guz-anton/c6fb1a26c25a3c0d4f6edad1291ec8ae 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
const fnBy = fn => x => y => !fn || !Math[fn] || !x || !y ? 0 : y < 0 ? 0 : y > x ? x : Math[fn] (10 * y / x) * x / 10; | |
// const ceilBy = max => y => !max || !y ? 0 : y < 0 ? 0 : y > max ? max : Math.ceil (10 * y / max) * max / 10; | |
const ceilBy = fnBy('ceil'); | |
const roundBy = fnBy('round'); | |
const floorBy = fnBy('floor'); | |
const fiveStarRating = ceilBy(5); | |
const oneHundredPoints = roundBy(100); | |
// Example | |
[1,3,4.5,'4.2','4.8',5,17] | |
.map(fiveStarRating) | |
.map(console.log.bind(console)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment