Skip to content

Instantly share code, notes, and snippets.

@Maxim-Filimonov
Last active September 19, 2015 17:42
Show Gist options
  • Select an option

  • Save Maxim-Filimonov/48c4ec6a3430fa7d8d2b to your computer and use it in GitHub Desktop.

Select an option

Save Maxim-Filimonov/48c4ec6a3430fa7d8d2b to your computer and use it in GitHub Desktop.

Revisions

  1. Maxim-Filimonov revised this gist Sep 14, 2015. No changes.
  2. Maxim-Filimonov created this gist Sep 14, 2015.
    7 changes: 7 additions & 0 deletions functional.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    // 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));
    };
    7 changes: 7 additions & 0 deletions original.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    // 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
    6 changes: 6 additions & 0 deletions ramda.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    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:"));
    11 changes: 11 additions & 0 deletions traditional.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    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;
    };