mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-07 18:07:49 +00:00
Ensure _.toInteger converts Infinity to an integer.
This commit is contained in:
11
lodash.js
11
lodash.js
@@ -9059,7 +9059,7 @@
|
|||||||
/**
|
/**
|
||||||
* Converts `value` to an integer.
|
* Converts `value` to an integer.
|
||||||
*
|
*
|
||||||
* **Note:** This function is based on [`ToInteger`](http://www.ecma-international.org/ecma-262/6.0/#sec-tointeger).
|
* **Note:** This function is loosely based on [`ToInteger`](http://www.ecma-international.org/ecma-262/6.0/#sec-tointeger).
|
||||||
*
|
*
|
||||||
* @static
|
* @static
|
||||||
* @memberOf _
|
* @memberOf _
|
||||||
@@ -9074,11 +9074,14 @@
|
|||||||
* _.toInteger(NaN);
|
* _.toInteger(NaN);
|
||||||
* // => 0
|
* // => 0
|
||||||
*
|
*
|
||||||
* _.toInteger(-Infinity);
|
* _.toInteger(-Infinity)
|
||||||
* // => -Infinity
|
* // => -Number.MAX_VALUE
|
||||||
*/
|
*/
|
||||||
function toInteger(value) {
|
function toInteger(value) {
|
||||||
return nativeFloor(value) || 0;
|
var result = nativeFloor(value) || 0;
|
||||||
|
return result == INFINITY
|
||||||
|
? MAX_VALUE
|
||||||
|
: (result == -INFINITY ? -MAX_VALUE : result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user