var _; //globals

/* This section uses a functional extension known as Underscore.js - http://documentcloud.github.com/underscore/
     "Underscore is a utility-belt library for JavaScript that provides a lot of the functional programming support
      that you would expect in Prototype.js (or Ruby), but without extending any of the built-in JavaScript objects.
      It's the tie to go along with jQuery's tux."
 */
describe("About Higher Order Functions", function () {

  it("should use filter to return array items that meet a criteria", function () {
    var numbers = [1,2,3];
    var odd = _(numbers).filter(function (x) { return x % 2 !== 0 });

    expect(odd).toEqual(FILL_ME_IN);
    expect(odd.length).toBe(FILL_ME_IN);
    expect(numbers.length).toBe(FILL_ME_IN);
  });

  it("should use 'map' to transform each element", function () {
    var numbers = [1, 2, 3];
    var numbersPlus1 = _(numbers).map(function(x) { return x + 1 });

    expect(numbersPlus1).toEqual(FILL_ME_IN);
    expect(numbers).toEqual(FILL_ME_IN);
  });

  it("should use 'reduce' to update the same result on each iteration", function () {
    var numbers = [1, 2, 3];
    var reduction = _(numbers).reduce(
            function(/* result from last call */ memo, /* current */ x) { return memo + x }, /* initial */ 0);

    expect(reduction).toBe(FILL_ME_IN);
    expect(numbers).toEqual(FILL_ME_IN);
  });

  it("should use 'forEach' for simple iteration", function () {
    var numbers = [1,2,3];
    var msg = "";
    var isEven = function (item) {
      msg += (item % 2) === 0;
    };

    _(numbers).forEach(isEven);

    expect(msg).toEqual(FILL_ME_IN);
    expect(numbers).toEqual(FILL_ME_IN);
  });

  it("should use 'all' to test whether all items pass condition", function () {
    var onlyEven = [2,4,6];
    var mixedBag = [2,4,5,6];

    var isEven = function(x) { return x % 2 === 0 };

    expect(_(onlyEven).all(isEven)).toBe(FILL_ME_IN);
    expect(_(mixedBag).all(isEven)).toBe(FILL_ME_IN);
  });

  it("should use 'any' to test if any items passes condition" , function () {
    var onlyEven = [2,4,6];
    var mixedBag = [2,4,5,6];

    var isEven = function(x) { return x % 2 === 0 };

    expect(_(onlyEven).any(isEven)).toBe(FILL_ME_IN);
    expect(_(mixedBag).any(isEven)).toBe(FILL_ME_IN);
  });

  it("should use range to generate an array", function() {
      expect(_.range(3)).toEqual(FILL_ME_IN);
      expect(_.range(1, 4)).toEqual(FILL_ME_IN);
      expect(_.range(0, -4, -1)).toEqual(FILL_ME_IN);
  });

  it("should use flatten to make nested arrays easy to work with", function() {
      expect(_([ [1, 2], [3, 4] ]).flatten()).toEqual(FILL_ME_IN);
  });

  it("should use chain() ... .value() to use multiple higher order functions", function() {
      var result = _([ [0, 1], 2 ]).chain()
                       .flatten()
                       .map(function(x) { return x+1 } )
                       .reduce(function (sum, x) { return sum + x })
                       .value();

      expect(result).toEqual(FILL_ME_IN);
  });

});


@@ -669,34 +669,30 @@
 dd).toEqual(
-FILL_ME_IN
+%5B1, 3%5D
 );%0A    expec
@@ -706,34 +706,25 @@
 ength).toBe(
-FILL_ME_IN
+2
 );%0A    expec
@@ -742,34 +742,25 @@
 ength).toBe(
-FILL_ME_IN
+3
 );%0A  %7D);%0A%0A  
@@ -950,34 +950,33 @@
 s1).toEqual(
-FILL_ME_IN
+%5B2, 3, 4%5D
 );%0A    expec
@@ -990,34 +990,33 @@
 rs).toEqual(
-FILL_ME_IN
+%5B1, 2, 3%5D
 );%0A  %7D);%0A%0A  
@@ -1302,34 +1302,25 @@
 ction).toBe(
-FILL_ME_IN
+6
 );%0A    expec
@@ -1334,34 +1334,33 @@
 rs).toEqual(
-FILL_ME_IN
+%5B1, 2, 3%5D
 );%0A  %7D);%0A%0A  
@@ -1593,34 +1593,40 @@
 sg).toEqual(
-FILL_ME_IN
+%22falsetruefalse%22
 );%0A    expec
@@ -1640,34 +1640,33 @@
 rs).toEqual(
-FILL_ME_IN
+%5B1, 2, 3%5D
 );%0A  %7D);%0A%0A  
@@ -1893,34 +1893,28 @@
 Even)).toBe(
-FILL_ME_IN
+true
 );%0A    expec
@@ -1941,34 +1941,29 @@
 Even)).toBe(
-FILL_ME_IN
+false
 );%0A  %7D);%0A%0A  
@@ -2188,34 +2188,28 @@
 Even)).toBe(
-FILL_ME_IN
+true
 );%0A    expec
@@ -2240,26 +2240,20 @@
 )).toBe(
-FILL_ME_IN
+true
 );%0A  %7D);
@@ -2342,34 +2342,33 @@
 3)).toEqual(
-FILL_ME_IN
+%5B0, 1, 2%5D
 );%0A      exp
@@ -2390,34 +2390,33 @@
 4)).toEqual(
-FILL_ME_IN
+%5B1, 2, 3%5D
 );%0A      exp
@@ -2443,34 +2443,39 @@
 1)).toEqual(
-FILL_ME_IN
+%5B0, -1, -2, -3%5D
 );%0A  %7D);%0A%0A  
@@ -2602,34 +2602,36 @@
 ()).toEqual(
-FILL_ME_IN
+%5B1, 2, 3, 4%5D
 );%0A  %7D);%0A%0A  
@@ -2991,18 +2991,9 @@
 ual(
-FILL_ME_IN
+6
 );%0A 

Complete koans 31-39 in 6.AboutHigherOrderfunctions.js