mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-10 02:47:50 +00:00
Bump to v3.0.0.
This commit is contained in:
29
collection/size.js
Normal file
29
collection/size.js
Normal file
@@ -0,0 +1,29 @@
|
||||
import isLength from '../internal/isLength';
|
||||
import keys from '../object/keys';
|
||||
|
||||
/**
|
||||
* Gets the size of `collection` by returning `collection.length` for
|
||||
* array-like values or the number of own enumerable properties for objects.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @category Collection
|
||||
* @param {Array|Object|string} collection The collection to inspect.
|
||||
* @returns {number} Returns the size of `collection`.
|
||||
* @example
|
||||
*
|
||||
* _.size([1, 2]);
|
||||
* // => 2
|
||||
*
|
||||
* _.size({ 'one': 1, 'two': 2, 'three': 3 });
|
||||
* // => 3
|
||||
*
|
||||
* _.size('pebbles');
|
||||
* // => 7
|
||||
*/
|
||||
function size(collection) {
|
||||
var length = collection ? collection.length : 0;
|
||||
return isLength(length) ? length : keys(collection).length;
|
||||
}
|
||||
|
||||
export default size;
|
||||
Reference in New Issue
Block a user