Last active
September 19, 2015 17:42
-
-
Save Maxim-Filimonov/48c4ec6a3430fa7d8d2b to your computer and use it in GitHub Desktop.
Playing with ramda
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
// Functional | |
var log = function(tag,val) { console.log(tag, val); return val; } | |
var isLightBackground = function(color) { | |
// 765 - max distance | |
log("color:",color); | |
return log("result:", log("distance:", xcolor.distance(color, 'white')) < (765/2)); | |
}; |
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
// Original | |
// Function determines is background light enough to show dark logo. | |
var isLightBackground = function(color) { | |
// 765 - max distance | |
return xcolor.distance(color, 'white') < (765/2); | |
}; | |
// The task is to add some logs to see what are results getting returned |
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
var R = require('ramda'); | |
var log = R.curry(function(tag,val) { console.log(tag, val); return val; }); | |
var distanceFromWhiteColor = R.flip(x.color.distance)('white'); | |
var isLightDistance = R.lt(765/2); | |
var isLightBackground = R.compose(log("result:"), isLighterDistance, log("distance:"), distanceFromWhiteColor, log("color:")); |
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
var isLightBackground = function(color) { | |
console.log("color:", color); | |
var distance = xcolor.distance(color, 'white'); | |
console.log("distance:", distance); | |
// 765 - max distance | |
var isLight = distance < (765/2)); | |
console.log("result:", isLight); | |
return isLight; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just playing with differente approaches