Skip to content

Instantly share code, notes, and snippets.

@gaand
Last active October 5, 2015 20:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gaand/65302e9a2227b74d2ee3 to your computer and use it in GitHub Desktop.
Save gaand/65302e9a2227b74d2ee3 to your computer and use it in GitHub Desktop.
Transomation
'use strict';

var transform = function transform(value, predicate, mutator) {
  if (predicate(value)) {
    return mutator(value);
  }
  return value;
};
var height = 69;
var isHeightInches = function isHeightInches(height) {
    return height < 100;
};
var inchesToCentimeters = function inchesToCentimeters(inches) {
    return height * 2.54;
};
height = transform(height, isHeightInches, inchesToCentimeters);
console.log(height);
height = transform(height, isHeightInches, inchesToCentimeters);
console.log(height);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment