O'Reilly logo

JavaScript: Functional Programming for JavaScript Developers by Dan Mantyla, Simon Timms, Ved Antani

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Appendix A. Common Functions for Functional Programming in JavaScript

This Appendix covers common functions for functional programming in JavaScript:

  • Array Functions:
    var flatten = function(arrays) {
      return arrays.reduce( function(p,n){
        return p.concat(n);
      });
    };
    
    var invert = function(arr) {
      return arr.map(function(x, i, a) {
        return a[a.length - (i+1)];
      });
    };
  • Binding Functions:
    var bind = Function.prototype.call.bind(Function.prototype.bind);
    var call = bind(Function.prototype.call, Function.prototype.call);
    var apply = bind(Function.prototype.call, Function.prototype.apply);
  • Category Theory:
    var checkTypes = function( typeSafeties ) { arrayOf(func)(arr(typeSafeties)); var argLength = typeSafeties.length; return function(args) { arr(args); if (args.length ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required