数学

返回lodash

_.add(augend, addend)

_.add(6, 4);
// => 10

_.subtract(minuend, subtrahend)

_.subtract(6, 4);
// => 2

_.divide(dividend, divisor)

_.divide(6, 4);
// => 1.5

_.multiply(multiplier, multiplicand)

_.multiply(6, 4);
// => 24

_.ceil(number, [precision=0])

根据 precision(精度) 向上舍入 number。(注: precision(精度)可以理解为保留几位小数。)

_.ceil(4.006);
// => 5

_.ceil(6.004, 2);
// => 6.01

_.ceil(6040, -2);
// => 6100

_.floor(number, [precision=0])

根据 precision(精度) 向下舍入 number。(注: precision(精度)可以理解为保留几位小数。)

_.floor(4.006);
// => 4

_.floor(0.046, 2);
// => 0.04

_.floor(4060, -2);
// => 4000

_.round(number, [precision=0])

根据 precision(精度) 四舍五入 number。

_.round(4.006);
// => 4

_.round(4.006, 2);
// => 4.01

_.round(4060, -2);
// => 4100

_.max(array)

计算 array 中的最大值。 如果 array 是 空的或者假值将会返回 undefined。

_.max([4, 2, 8, 6]);
// => 8

_.max([]);
// => undefined

.maxBy(array, [iteratee=.identity])

这个方法类似_.max 除了它接受 iteratee 来调用 array中的每一个元素,来生成其值排序的标准。 iteratee 会调用1个参数: (value) 。

var objects = [{ 'n': 1 }, { 'n': 2 }];

_.maxBy(objects, function(o) { return o.n; });
// => { 'n': 2 }

// The `_.property` iteratee shorthand.
_.maxBy(objects, 'n');
// => { 'n': 2 }

_.mean(array)

计算 array 的平均值。

_.mean([4, 2, 8, 6]);
// => 5

.meanBy(array, [iteratee=.identity])

这个方法类似_.mean, 除了它接受 iteratee 来调用 array中的每一个元素,来生成其值排序的标准。 iteratee 会调用1个参数: (value) 。

var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }];

_.meanBy(objects, function(o) { return o.n; });
// => 5

// The `_.property` iteratee shorthand.
_.meanBy(objects, 'n');
// => 5

_.min(array)

计算 array 中的最小值。 如果 array 是 空的或者假值将会返回 undefined

_.min([4, 2, 8, 6]);
// => 2

_.min([]);
// => undefined

.minBy(array, [iteratee=.identity])

这个方法类似_.min 除了它接受 iteratee 来调用 array中的每一个元素,来生成其值排序的标准。 iteratee 会调用1个参数: (value) 。

var objects = [{ 'n': 1 }, { 'n': 2 }];

_.minBy(objects, function(o) { return o.n; });
// => { 'n': 1 }

// The `_.property` iteratee shorthand.
_.minBy(objects, 'n');
// => { 'n': 1 }

_.sum(array)

_.sum([4, 2, 8, 6]);
// => 20

.sumBy(array, [iteratee=.identity])

这个方法类似_.sum 除了它接受 iteratee 来调用 array中的每一个元素,来生成其值排序的标准。 iteratee 会调用1个参数: (value) 。

var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }];

_.sumBy(objects, function(o) { return o.n; });
// => 20

// The `_.property` iteratee shorthand.
_.sumBy(objects, 'n');
// => 20