var reduce = require('..'); describe('reduce', function(){ describe('when adding prev and current', function(){ it('should be sum all the values', function(){ var numbers = [2,2,2]; var fn = function(prev, curr){ return prev + curr; }; var a = numbers.reduce(fn); var b = reduce(numbers, fn); a.should.equal(6); b.should.equal(a); }); }); describe('when passing in an initial value', function(){ it('should default to it', function(){ var items = []; var fn = function(prev){ return prev; }; var a = items.reduce(fn, 'foo'); var b = reduce(items, fn, 'foo'); a.should.equal('foo'); b.should.equal(a); }); it('should start with it', function(){ var items = [10, 10]; var fn = function(prev, curr){ return prev + curr; }; var a = items.reduce(fn, 10); var b = reduce(items, fn, 10); a.should.equal(30); b.should.equal(a); }); }); });
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 19553 | swellard | Move and rename clients | ||
//guest/perforce_software/helix-web-services/main/source/clients/2016.1.0/javascript/node_modules/reduce-component/test/reduce.js | |||||
#1 | 18810 | tjuricek |
First-pass at JavaScript client SDK. JavaScript requires Node with Gulp to "browserfy" the library. It's the easiest way I found to use the swagger-js project; bundle up a wrapping method. There is no JavaScript reference guide. The swagger-js doesn't really document what they do very well, actually. Overall I'm not particularly impressed by swagger-js, it was hard to even figure out what the right method syntax was. We may want to invest time in doing it better. This required setting CORS response headers, which are currently defaulted to a fairly insecure setting. |