backbone-calculate
The calculation methods are inspired by Rails and taken a bit further. This package uses underscore-calculate under the hood which only considers numbers, and returns undefined
for empty collections. We use this package to graph data from collections.
Each calculation method either returns a value, an array of values, or an object with fields and values depending on parameters. For each example, consider the following collection:
var collection = ;collection;collection; // the following model won't end up in any calculationscollection;
average
collection;// 1 collection;// [ 1, 3 ] collection// { a: 1, b: 3 } collection;// 4
sum
collection;// 2 collection;// [ 2, 6 ] collection// { a: 2, b: 6 } collection;// 8
maximum
collection;// 2 collection;// [ 2, 4 ] collection// { a: 2, b: 4 } collection;// 8
minimum
collection;// 0 collection;// [ 0, 2 ] collection// { a: 0, b: 2 } collection;// 0
Notes
To use backbone-calculate, copy the backbone.calculate.js
file into your project and include it after backbone.
License: MIT