This repository has been archived by the owner on Jan 12, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Garrett Johnson
committed
Nov 8, 2012
1 parent
4011117
commit 346d59f
Showing
6 changed files
with
77 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
components | ||
build | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"name": "reduce", | ||
"description": "Array reduce component", | ||
"version": "0.0.1", | ||
"devDependencies": { | ||
"mocha": "*", | ||
"should": "*" | ||
}, | ||
"component": { | ||
"scripts": { | ||
"reduce": "index.js" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
|
||
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); | ||
}); | ||
}); | ||
|
||
}); |