Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@skava/modules / ___dist / chain-able / test / loop / map / mapAcum.js
Size: Mime:
"use strict";

const mapAccum = require("../../../src/deps/loop/map/mapAcum");

describe('mapAccum', function () {
  var add = function add(a, b) {
    return [a + b, a + b];
  };

  var mult = function mult(a, b) {
    return [a * b, a * b];
  };

  var concat = function concat(a, b) {
    return [a.concat(b), a.concat(b)];
  };

  it('map and accumulate simple functions over arrays with the supplied accumulator', function () {
    eq(mapAccum(add, 0, [1, 2, 3, 4]), [10, [1, 3, 6, 10]]);
    eq(mapAccum(mult, 1, [1, 2, 3, 4]), [24, [1, 2, 6, 24]]);
  });
  it('returns the list and accumulator for an empty array', function () {
    eq(mapAccum(add, 0, []), [0, []]);
    eq(mapAccum(mult, 1, []), [1, []]);
    eq(mapAccum(concat, [], []), [[], []]);
  });
  it('is curried', function () {
    var addOrConcat = mapAccum(add);
    var sum = addOrConcat(0);
    var cat = addOrConcat('');
    eq(sum([1, 2, 3, 4]), [10, [1, 3, 6, 10]]);
    eq(cat(['1', '2', '3', '4']), ['1234', ['1', '12', '123', '1234']]);
  });
  it('correctly reports the arity of curried versions', function () {
    var sum = mapAccum(add, 0);
    eq(sum.length, 1);
  });
});