mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-08 18:17:48 +00:00
Improve documentation of toLength by including examples. [ci skip]
This commit is contained in:
committed by
John-David Dalton
parent
b84c336855
commit
ecaee16d23
19
lodash.js
19
lodash.js
@@ -9892,6 +9892,25 @@
|
|||||||
* @category Lang
|
* @category Lang
|
||||||
* @param {*} value The value to convert.
|
* @param {*} value The value to convert.
|
||||||
* @return {number} Returns the converted integer.
|
* @return {number} Returns the converted integer.
|
||||||
|
* @example
|
||||||
|
*
|
||||||
|
* _.toLength(NaN);
|
||||||
|
* // => 0
|
||||||
|
*
|
||||||
|
* _.toLength(Infinity);
|
||||||
|
* // => 4294967295
|
||||||
|
*
|
||||||
|
* var answer = {
|
||||||
|
* valueOf: function () {
|
||||||
|
* return 1;
|
||||||
|
* },
|
||||||
|
* toString: function () {
|
||||||
|
* return 'one';
|
||||||
|
* }
|
||||||
|
* };
|
||||||
|
*
|
||||||
|
* _.toLength(answer);
|
||||||
|
* // => 1
|
||||||
*/
|
*/
|
||||||
function toLength(value) {
|
function toLength(value) {
|
||||||
return clamp(toInteger(value), 0, MAX_ARRAY_LENGTH);
|
return clamp(toInteger(value), 0, MAX_ARRAY_LENGTH);
|
||||||
|
|||||||
Reference in New Issue
Block a user