From 2e248d1ca809dc2220daffe34e99817d8b6b392f Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Tue, 15 Sep 2015 20:37:53 -0700 Subject: [PATCH] Ensure `_.toInteger` converts `Infinity` to an integer. --- lodash.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lodash.js b/lodash.js index 917e2c3fc..bb6ca5668 100644 --- a/lodash.js +++ b/lodash.js @@ -9059,7 +9059,7 @@ /** * 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 * @memberOf _ @@ -9074,11 +9074,14 @@ * _.toInteger(NaN); * // => 0 * - * _.toInteger(-Infinity); - * // => -Infinity + * _.toInteger(-Infinity) + * // => -Number.MAX_VALUE */ function toInteger(value) { - return nativeFloor(value) || 0; + var result = nativeFloor(value) || 0; + return result == INFINITY + ? MAX_VALUE + : (result == -INFINITY ? -MAX_VALUE : result); } /**