Ad
Arrays
Data Types
Functions
Control Flow
Basic Language Features
Fundamentals
Language Syntax
Declarative Programming
Programming Paradigms
Lambdas
Functional Programming
Higher-order Functions

A slightly shorter version

Code
Diff
  • // This is just an interesting alternative way to build an array,
    // almost like a declarative literal - Very cool stuff!
    
    // See test cases for syntax.
    
    function chain(element) {
      var sectionBuilder = function(elem) {
        sectionBuilder.end.push(elem);
        return sectionBuilder;
      };
      sectionBuilder.end = [];
      return sectionBuilder(element);
    }
    • // This is just an interesting alternative way to build an array,
    • // almost like a declarative literal - Very cool stuff!
    • // See test cases for syntax.
    • function chain(element) {
    • var array = [element];
    • var sectionBuilder = function(elem) {
    • array.push(elem);
    • sectionBuilder.end = array;
    • sectionBuilder.end.push(elem);
    • return sectionBuilder;
    • };
    • sectionBuilder.end = array;
    • return sectionBuilder;
    • sectionBuilder.end = [];
    • return sectionBuilder(element);
    • }