Last active
November 25, 2018 13:35
-
-
Save oguzcan-yavuz/89c18077429c702ee36749a125770b01 to your computer and use it in GitHub Desktop.
rating credit scores exercise
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
import { map, cond, gte, lte, flip, always } from 'ramda' | |
import scores from './scores.json' | |
const flippedGTE = flip(gte) | |
const flippedLTE = flip(lte) | |
const rater = cond([ | |
[ flippedGTE(800), always(`excellent!`) ], | |
[ flippedGTE(700), always(`good`) ], | |
[ flippedGTE(650), always(`fair`) ], | |
[ flippedLTE(649), always(`poor`) ], | |
]) | |
const createReview = (score) => `${score} is ${rater(score)}` | |
const getCreditScoreRatings = map(createReview) | |
const result = getCreditScoreRatings(scores) | |
console.log({ result }) |
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
import { cond, gte, lte, map } from 'ramda'; | |
import scores from './scores.json'; | |
const reviewCreditScore = cond([ | |
[lte(800), (score) => `${score} is excellent!`], | |
[lte(700), (score) => `${score} is good`], | |
[lte(650), (score) => `${score} is fair`], | |
[gte(649), (score) => `${score} is poor`] | |
]); | |
const reviewCreditScores = map(reviewCreditScore); | |
console.log(reviewCreditScores(scores)); |
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
[ | |
631, | |
604, | |
527, | |
503, | |
800, | |
579, | |
673, | |
513, | |
808, | |
701, | |
833, | |
795, | |
644, | |
649, | |
557, | |
556, | |
548, | |
815, | |
737, | |
687, | |
777, | |
635, | |
653, | |
829, | |
593, | |
511, | |
663, | |
737, | |
713, | |
797, | |
608, | |
577, | |
636, | |
655, | |
850, | |
540, | |
626, | |
609, | |
737, | |
570, | |
720, | |
668, | |
789, | |
658, | |
615, | |
628, | |
519, | |
611, | |
766, | |
811 | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment