Earn extra honor and gain new allies!
Honor is earned for each new codewarrior who joins.
Learn more
Arrays
Functions
Control Flow
Basic Language Features
Fundamentals
Language Syntax
Declarative Programming
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);
    }
  • 11
    // This is just an interesting alternative way to build an array,
    
    22
    // almost like a declarative literal - Very cool stuff!
    
    33
    44
    // See test cases for syntax.
    
    55
    66
    function chain(element) {
    
    7
      var array = [element];
    
    88
      var sectionBuilder = function(elem) {
    
    9
        array.push(elem);
    
    10
        sectionBuilder.end = array;
    
    8+
        sectionBuilder.end.push(elem);
    
    1111
        return sectionBuilder;
    
    1212
      };
    
    13
      sectionBuilder.end = array;
    
    14
      return sectionBuilder;
    
    11+
      sectionBuilder.end = [];
    
    12+
      return sectionBuilder(element);
    
    1515
    }