JSPM

compute-sum

1.1.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 351
  • Score
    100M100P100Q82539F

Computes the sum of an array.

Package Exports

  • compute-sum

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (compute-sum) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Sum

NPM version Build Status Coverage Status Dependencies

Computes the sum of an array.

Installation

$ npm install compute-sum

For use in the browser, use browserify.

Usage

var sum = require( 'compute-sum' );

sum( arr[, accessor] )

Computes the sum of an array. For numeric arrays,

var data = [ 2, 4, 5, 3, 4 ];

var s = sum( data );
// returns 18

For non-numeric arrays, provide an accessor function for accessing numeric array values

var data = [
    {'x':2},
    {'x':4},
    {'x':5},
    {'x':3},
    {'x':4},
];

function getValue( d ) {
    return d.x;
}

var s = sum( data, getValue );
// returns 18

Note: if provided an empty array, the function returns null.

Examples

var sum = require( 'compute-sum' );

var data = new Array( 1000 );
for ( var i = 0; i < data.length; i++ ) {
    data[ i ] = Math.random() * 100;
}

console.log( sum( data ) );

To run the example code from the top-level application directory,

$ node ./examples/index.js

Tests

Unit

Unit tests use the Mocha test framework with Chai assertions. To run the tests, execute the following command in the top-level application directory:

$ make test

All new feature development should have corresponding unit tests to validate correct functionality.

Test Coverage

This repository uses Istanbul as its code coverage tool. To generate a test coverage report, execute the following command in the top-level application directory:

$ make test-cov

Istanbul creates a ./reports/coverage directory. To access an HTML version of the report,

$ make view-cov

License

MIT license.

Copyright © 2014. Athan Reines.