博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Lodash 中文文档 (v3.10.1) - “Math” 方法
阅读量:7043 次
发布时间:2019-06-28

本文共 3069 字,大约阅读时间需要 10 分钟。

Lodash 中文文档 (v3.10.1) - “Math” 方法

Translated by

Original Docs:

“Math” 方法

_.add(augend, addend)

将两个数相加。

参数

  1. augend (number) : 待求和的第一个数值

  2. addend (number) : 待求和的第二个数值

返回

(number) : 返回两数的和

示例

_.add(6, 4);// → 10

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

根据 precisionnumber 向上取整。

参数

  1. n (number) : 待向上取整的数值

  2. [precision=0] (number) : 向上取整的精度

返回

(number) : 返回向上取整后的值

示例

_.ceil(4.006);// → 5_.ceil(6.004, 2);// → 6.01_.ceil(6040, -2);// → 6100

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

根据 precisionnumber 向下取整。

参数

  1. n (number) : 待向下取整的数值

  2. [precision=0] (number) : 向下取整的精度

返回

(number) : 返回向下取整后的数值

示例

_.floor(4.006);// → 4_.floor(0.046, 2);// → 0.04_.floor(4060, -2);// → 4000

_.max(collection, [iteratee], [thisArg])

获取 collection 中的最大值。如果 collection 为空或是假值,则会返回 -Infinity。如果提供了迭代器函数,那么其将被作用于 collection 中的每个值以来生成值排序的标准。iteratee 将绑定 thisArg 并在执行时传入三个参数:value, index, collection

如果提供的是属性名,那么 predicate 将创建 _.property 风格的回调函数,并返回给定元素的属性的值。

如果值还提供了 thisArg,那么 predicate 将创建 _.matchesProperty 风格的回调,并在元素含有匹配的属性值的时候返回 true,否则返回 false

如果提供的是对象,那么 predicate 将创建 _.matches 风格的回调函数,并在匹配给定对象的属性的元素时返回 true,否则返回 false

参数

  1. collection (Array|Object|string) : 待迭代的集合

  2. [iteratee] (Function|Object|string) : 每次迭代执行的函数

  3. [thisArg] (*) : iteratee 绑定的 this

返回

(*) : 返回最大值

示例

_.max([4, 2, 8, 6]);// → 8_.max([]);// → -Infinityvar users = [  { 'user': 'barney', 'age': 36 },  { 'user': 'fred',   'age': 40 }];_.max(users, function(chr) {  return chr.age;});// → { 'user': 'fred', 'age': 40 }// 使用 `_.property` 回调函数简称_.max(users, 'age');// → { 'user': 'fred', 'age': 40 }

_.min(collection, [iteratee], [thisArg])

获取 collection 中的最小值。如果 collection 为空或是假值,则会返回 -Infinity。如果提供了迭代器函数,那么其将被作用于 collection 中的每个值以来生成值排序的标准。iteratee 将绑定 thisArg 并在执行时传入三个参数:value, index, collection

如果提供的是属性名,那么 predicate 将创建 _.property 风格的回调函数,并返回给定元素的属性的值。

如果值还提供了 thisArg,那么 predicate 将创建 _.matchesProperty 风格的回调,并在元素含有匹配的属性值的时候返回 true,否则返回 false

如果提供的是对象,那么 predicate 将创建 _.matches 风格的回调函数,并在匹配给定对象的属性的元素时返回 true,否则返回 false

参数

  1. collection (Array|Object|string) : 待迭代的集合

  2. [iteratee] (Function|Object|string) : 每次迭代执行的函数

  3. [thisArg] (*) : iteratee 绑定的 this

返回

(*) : 返回最小值

示例

_.min([4, 2, 8, 6]);// → 2_.min([]);// → Infinityvar users = [  { 'user': 'barney', 'age': 36 },  { 'user': 'fred',   'age': 40 }];_.min(users, function(chr) {  return chr.age;});// → { 'user': 'barney', 'age': 36 }// using the `_.property` callback shorthand_.min(users, 'age');// → { 'user': 'barney', 'age': 36 }

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

precision 四舍五入 n

参数

  1. n (number) : 待计算的数值

  2. [precision=0] (number) : 四舍五入的精度

返回

(number) : 返回四舍五入后的数值

示例

_.round(4.006);// → 4_.round(4.006, 2);// → 4.01_.round(4060, -2);// → 4100

_.sum(collection, [iteratee], [thisArg])

Gets the sum of the values in collection.

获取 collection 的值的和

参数

  1. collection (Array|Object|string) : 待迭代的集合

  2. [iteratee] (Function|Object|string) : 每次迭代执行的函数

  3. [thisArg] (*) : iteratee 绑定的 this

返回

(number) : 返回计算的和

示例

_.sum([4, 6]);// → 10_.sum({ 'a': 4, 'b': 6 });// → 10var objects = [  { 'n': 4 },  { 'n': 6 }];_.sum(objects, function(object) {  return object.n;});// → 10// 使用 `_.property` 回调函数简称_.sum(objects, 'n');// → 10

转载地址:http://alhal.baihongyu.com/

你可能感兴趣的文章
ASP.NET MVC——Action的执行
查看>>
poj2871
查看>>
将字符串切割成数组 componentsSeparatedByString
查看>>
HDU-4472 Count 递推
查看>>
大型网站核心技术
查看>>
吸收遍历Google Code jam 2013 Round 1B A题
查看>>
Android获取设备型号、SDK版本及其系统版本
查看>>
windows中如何在命令行启动启动程序
查看>>
布局文件Android ListView入门知识--各种Adapter配合使用
查看>>
项目文件跟Google学习Android开发-工具篇-Android Studio入门
查看>>
最火的Android开源项目(1)
查看>>
C#中winform窗体常用设置
查看>>
win8 sqlserver2008 附加数据库错误: 5120
查看>>
HTML <div> 标签的 align 属性
查看>>
SQL Server2008附加数据库之后显示为只读时解决方法 .
查看>>
Lazy Load, 延迟加载图片的 jQuery 插件【备忘】
查看>>
Linux下nagios网络监控与/proc/net/tcp文件详解
查看>>
JavaBean 基础概念、使用实例及代码分析
查看>>
(转)typedef 函数指针的用法
查看>>
谈Mysql索引
查看>>