Skip to content

Instantly share code, notes, and snippets.

@Maxim-Filimonov
Last active September 19, 2015 17:42
Show Gist options
  • Save Maxim-Filimonov/48c4ec6a3430fa7d8d2b to your computer and use it in GitHub Desktop.
Save Maxim-Filimonov/48c4ec6a3430fa7d8d2b to your computer and use it in GitHub Desktop.
Playing with ramda
// 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));
};
// 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
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:"));
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;
};
@Maxim-Filimonov
Copy link
Author

Just playing with differente approaches

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment