Skip to content

Commit

Permalink
Fn.sum: Update comments and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lyzadanger committed Sep 22, 2016
1 parent bc62b61 commit 79de80c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
13 changes: 9 additions & 4 deletions lib/fn.js
Expand Up @@ -170,10 +170,15 @@ Fn.square = function(x) {
return x * x;
};

// Fn.sum( values )
//
// Returns the sum of all values from array
//
/**
* Get a sum for all the values in an Array. This works best if the elements
* in the Array are Numbers.
*
* @param {Array} values
* @return {Number | String} - You probably want a Number so you'll want to
* pass a values Array entirely consisting of
* numeric elements.
*/
Fn.sum = function sum(values) {
var vals;
if (Array.isArray(values)) {
Expand Down
8 changes: 6 additions & 2 deletions test/fn.js
Expand Up @@ -135,17 +135,21 @@ exports["Fn"] = {
},

sum: function(test) {
test.expect(4);
test.expect(6);

var a = 0,
b = 1,
c = [],
d = [0, 1];
d = [0, 1],
e = ["finger", 3, 4],
f = [{foo: "bar"}, 2, 3];

test.equal(Fn.sum(a), 0);
test.equal(Fn.sum(b), 1);
test.equal(Fn.sum(c), 0);
test.equal(Fn.sum(d), 1);
test.equal(Fn.sum(e), "0finger34");
test.equal(Fn.sum(f), "0[object Object]23");

test.done();
},
Expand Down

0 comments on commit 79de80c

Please sign in to comment.