Last active
January 28, 2020 04:01
-
-
Save yosevu/98d4fd57ca4983d15f473e37aa2ca312 to your computer and use it in GitHub Desktop.
getNumberOfStars
This file contains 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
// Fixtures | |
const FILLED_STAR = '<filled/>'; | |
const EMPTY_STAR = '<empty/>'; | |
const MAX_STARS = 5; | |
const numberOfStars = 3; | |
// Version 1 | |
R.join('', | |
R.concat( | |
R.times(R.always(FILLED_STAR), numberOfStars), | |
R.times(R.always(EMPTY_STAR), R.subtract(MAX_STARS, numberOfStars)) | |
) | |
) | |
// Version 2 | |
// getFilledStars :: Number -> [String] | |
const getFilledStars = R.times(R.always(FILLED_STAR)); | |
// getEmptyStars :: Number -> [String] | |
const getEmptyStars = numberOfStars => R.times( | |
R.always(EMPTY_STAR), | |
R.subtract(MAX_STARS, numberOfStars) | |
); | |
// getNumberOfStars :: Number -> String | |
const getNumberOfStars = R.pipe( | |
R.converge(R.concat, [getFilledStars, getEmptyStars]), | |
R.join('') | |
); | |
getNumberOfStars(numberOfStars); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment