mingo
Version:
MongoDB query language for in-memory objects
14 lines (13 loc) • 361 B
JavaScript
import { isArray, isNumber } from "../../util";
import { $push } from "./push";
const $sum = (collection, expr, options) => {
if (!isArray(collection))
return 0;
if (isNumber(expr))
return collection.length * expr;
const nums = $push(collection, expr, options).filter(isNumber);
return nums.reduce((acc, n) => acc + n, 0);
};
export {
$sum
};