mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-01 15:57:48 +00:00
Add fast path for numbers in _.toNumber.
This commit is contained in:
@@ -11022,6 +11022,9 @@
|
||||
* // => 3
|
||||
*/
|
||||
function toNumber(value) {
|
||||
if (typeof value == 'number') {
|
||||
return value;
|
||||
}
|
||||
if (isSymbol(value)) {
|
||||
return NAN;
|
||||
}
|
||||
|
||||
14
test/test.js
14
test/test.js
@@ -21872,6 +21872,20 @@
|
||||
return '+' + string;
|
||||
}
|
||||
|
||||
QUnit.test('`_.' + methodName + '` should pass thru primitive number values', function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
var values = [0, 1, NaN];
|
||||
|
||||
var expected = lodashStable.map(values, function(value) {
|
||||
return (!isToNumber && value !== value) ? 0 : value;
|
||||
});
|
||||
|
||||
var actual = lodashStable.map(values, func);
|
||||
|
||||
assert.deepEqual(actual, expected);
|
||||
});
|
||||
|
||||
QUnit.test('`_.' + methodName + '` should convert number primitives and objects to numbers', function(assert) {
|
||||
assert.expect(1);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user