From 4cf2e83418e330f360978e9d87067dc62b607e7a Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Fri, 29 Jun 2012 20:41:12 -0400 Subject: [PATCH] Add `_.zipObject`. Former-commit-id: 0fe17adc359fbc608025dced32f6dd509d019413 --- build.js | 3 +- build/pre-compile.js | 3 +- doc/README.md | 131 ++++++++++++++++++++++++++----------------- lodash.js | 39 +++++++++++-- lodash.min.js | 6 +- test/test.js | 13 ++++- 6 files changed, 132 insertions(+), 63 deletions(-) diff --git a/build.js b/build.js index 49bfb1a07..19223a1a9 100755 --- a/build.js +++ b/build.js @@ -181,7 +181,8 @@ 'values': [], 'without': ['indexOf'], 'wrap': [], - 'zip': ['max', 'pluck'] + 'zip': ['max', 'pluck'], + 'zipObject': [] }; /** Collections of method names */ diff --git a/build/pre-compile.js b/build/pre-compile.js index a8eeba50c..91c9a3996 100644 --- a/build/pre-compile.js +++ b/build/pre-compile.js @@ -183,7 +183,8 @@ 'VERSION', 'without', 'wrap', - 'zip' + 'zip', + 'zipObject' ]; /*--------------------------------------------------------------------------*/ diff --git a/doc/README.md b/doc/README.md index 5f63b78c7..34f96bb1f 100644 --- a/doc/README.md +++ b/doc/README.md @@ -91,6 +91,7 @@ * [`_.without`](#_withoutarray--value1-value2-) * [`_.wrap`](#_wrapfunc-wrapper--arg1-arg2-) * [`_.zip`](#_ziparray1-array2-) +* [`_.zipObject`](#_zipobjectkeys) @@ -147,7 +148,7 @@ The `lodash` function. ### `_.VERSION` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L3386 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L3416 "View in source") [Ⓣ][1] *(String)*: The semantic version number. @@ -159,7 +160,7 @@ The `lodash` function. ### `_.after(n, func)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L1804 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L1834 "View in source") [Ⓣ][1] Creates a new function that is restricted to executing only after it is called `n` times. @@ -187,7 +188,7 @@ _.forEach(notes, function(note) { ### `_.bind(func [, thisArg, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L1858 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L1888 "View in source") [Ⓣ][1] Creates a new function that, when called, invokes `func` with the `this` binding of `thisArg` and prepends any additional `bind` arguments to those passed to the bound function. Lazy defined methods may be bound by passing the object they are bound to as `func` and the method name as `thisArg`. @@ -238,7 +239,7 @@ func(); ### `_.bindAll(object [, methodName1, methodName2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L1928 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L1958 "View in source") [Ⓣ][1] Binds methods on `object` to `object`, overwriting the existing method. If no method names are provided, all the function properties of `object` will be bound. @@ -269,7 +270,7 @@ jQuery('#lodash_button').on('click', buttonView.onClick); ### `_.chain(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L3311 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L3341 "View in source") [Ⓣ][1] Wraps the value in a `lodash` wrapper object. @@ -303,7 +304,7 @@ var youngest = _.chain(stooges) ### `_.clone(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L2254 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L2284 "View in source") [Ⓣ][1] Create a shallow clone of the `value`. Any nested objects or arrays will be assigned by reference and not cloned. @@ -351,7 +352,7 @@ _.compact([0, 1, false, 2, '', 3]); ### `_.compose([func1, func2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L1960 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L1990 "View in source") [Ⓣ][1] Creates a new function that is the composition of the passed functions, where each function consumes the return value of the function that follows. In math terms, composing the functions `f()`, `g()`, and `h()` produces `f(g(h()))`. @@ -403,7 +404,7 @@ _.contains([1, 2, 3], 3); ### `_.debounce(func, wait, immediate)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L1993 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L2023 "View in source") [Ⓣ][1] Creates a new function that will delay the execution of `func` until after `wait` milliseconds have elapsed since the last time it was invoked. Pass `true` for `immediate` to cause debounce to invoke `func` on the leading, instead of the trailing, edge of the `wait` timeout. Subsequent calls to the debounced function will return the result of the last `func` call. @@ -429,7 +430,7 @@ jQuery(window).on('resize', lazyLayout); ### `_.defaults(object [, defaults1, defaults2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L2277 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L2307 "View in source") [Ⓣ][1] Assigns missing properties on `object` with default values from the defaults objects. Once a property is set, additional defaults of the same property will be ignored. @@ -455,7 +456,7 @@ _.defaults(iceCream, { 'flavor': 'vanilla', 'sprinkles': 'rainbow' }); ### `_.defer(func [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L2058 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L2088 "View in source") [Ⓣ][1] Defers executing the `func` function until the current call stack has cleared. Additional arguments are passed to `func` when it is invoked. @@ -480,7 +481,7 @@ _.defer(function() { alert('deferred'); }); ### `_.delay(func, wait [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L2038 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L2068 "View in source") [Ⓣ][1] Executes the `func` function after `wait` milliseconds. Additional arguments are passed to `func` when it is invoked. @@ -532,7 +533,7 @@ _.difference([1, 2, 3, 4, 5], [5, 2, 10]); ### `_.escape(string)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L2983 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L3013 "View in source") [Ⓣ][1] Escapes a string for inclusion in HTML, replacing `&`, `<`, `"`, and `'` characters. @@ -582,7 +583,7 @@ _.every([true, 1, null, 'yes'], Boolean); ### `_.extend(object [, source1, source2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L2296 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L2326 "View in source") [Ⓣ][1] Copies enumerable properties from the source objects to the `destination` object. Subsequent sources will overwrite propery assignments of previous sources. @@ -742,7 +743,7 @@ _.forEach({ 'one': 1, 'two': 2, 'three': 3 }, alert); ### `_.forIn(object, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L2325 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L2355 "View in source") [Ⓣ][1] Iterates over `object`'s own and inherited enumerable properties, executing the `callback` for each property. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, key, object)*. @@ -778,7 +779,7 @@ _.forIn(new Dog('Dagny'), function(value, key) { ### `_.forOwn(object, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L2348 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L2378 "View in source") [Ⓣ][1] Iterates over `object`'s own enumerable properties, executing the `callback` for each property. The `callback` is bound to `thisArg` and invoked with `3` arguments; *(value, key, object)*. @@ -806,7 +807,7 @@ _.forOwn({ '0': 'zero', '1': 'one', 'length': 2 }, function(num, key) { ### `_.functions(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L2365 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L2395 "View in source") [Ⓣ][1] Produces a sorted array of the enumerable properties, own and inherited, of `object` that have function values. @@ -862,7 +863,7 @@ _.groupBy(['one', 'two', 'three'], 'length'); ### `_.has(object, property)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L2388 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L2418 "View in source") [Ⓣ][1] Checks if the specified object `property` exists and is a direct property, instead of an inherited property. @@ -887,7 +888,7 @@ _.has({ 'a': 1, 'b': 2, 'c': 3 }, 'b'); ### `_.identity(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L3002 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L3032 "View in source") [Ⓣ][1] This function returns the first argument passed to it. Note: It is used throughout Lo-Dash as a default callback. @@ -1023,7 +1024,7 @@ _.invoke([123, 456], String.prototype.split, ''); ### `_.isArguments(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L2408 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L2438 "View in source") [Ⓣ][1] Checks if `value` is an `arguments` object. @@ -1050,7 +1051,7 @@ _.isArguments([1, 2, 3]); ### `_.isArray(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L2434 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L2464 "View in source") [Ⓣ][1] Checks if `value` is an array. @@ -1077,7 +1078,7 @@ _.isArray([1, 2, 3]); ### `_.isBoolean(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L2451 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L2481 "View in source") [Ⓣ][1] Checks if `value` is a boolean *(`true` or `false`)* value. @@ -1101,7 +1102,7 @@ _.isBoolean(null); ### `_.isDate(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L2468 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L2498 "View in source") [Ⓣ][1] Checks if `value` is a date. @@ -1125,7 +1126,7 @@ _.isDate(new Date); ### `_.isElement(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L2485 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L2515 "View in source") [Ⓣ][1] Checks if `value` is a DOM element. @@ -1149,7 +1150,7 @@ _.isElement(document.body); ### `_.isEmpty(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L2506 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L2536 "View in source") [Ⓣ][1] Checks if `value` is empty. Arrays or strings with a length of `0` and objects with no own enumerable properties are considered "empty". @@ -1176,7 +1177,7 @@ _.isEmpty({}); ### `_.isEqual(a, b [, stack])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L2540 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L2570 "View in source") [Ⓣ][1] Performs a deep comparison between two values to determine if they are equivalent to each other. @@ -1208,7 +1209,7 @@ _.isEqual(moe, clone); ### `_.isFinite(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L2701 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L2731 "View in source") [Ⓣ][1] Checks if `value` is a finite number. Note: This is not the same as native `isFinite`, which will return true for booleans and other values. See http://es5.github.com/#x15.1.2.5. @@ -1238,7 +1239,7 @@ _.isFinite(Infinity); ### `_.isFunction(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L2718 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L2748 "View in source") [Ⓣ][1] Checks if `value` is a function. @@ -1262,7 +1263,7 @@ _.isFunction(''.concat); ### `_.isNaN(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L2770 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L2800 "View in source") [Ⓣ][1] Checks if `value` is `NaN`. Note: This is not the same as native `isNaN`, which will return true for `undefined` and other values. See http://es5.github.com/#x15.1.2.4. @@ -1295,7 +1296,7 @@ _.isNaN(undefined); ### `_.isNull(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L2793 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L2823 "View in source") [Ⓣ][1] Checks if `value` is `null`. @@ -1322,7 +1323,7 @@ _.isNull(undefined); ### `_.isNumber(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L2810 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L2840 "View in source") [Ⓣ][1] Checks if `value` is a number. @@ -1346,7 +1347,7 @@ _.isNumber(8.4 * 5; ### `_.isObject(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L2739 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L2769 "View in source") [Ⓣ][1] Checks if `value` is the language type of Object. *(e.g. arrays, functions, objects, regexps, `new Number(0)*`, and `new String('')`) @@ -1373,7 +1374,7 @@ _.isObject(1); ### `_.isRegExp(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L2827 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L2857 "View in source") [Ⓣ][1] Checks if `value` is a regular expression. @@ -1397,7 +1398,7 @@ _.isRegExp(/moe/); ### `_.isString(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L2844 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L2874 "View in source") [Ⓣ][1] Checks if `value` is a string. @@ -1421,7 +1422,7 @@ _.isString('moe'); ### `_.isUndefined(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L2862 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L2892 "View in source") [Ⓣ][1] Checks if `value` is `undefined`. @@ -1445,7 +1446,7 @@ _.isUndefined(void 0); ### `_.keys(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L2879 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L2909 "View in source") [Ⓣ][1] Produces an array of object`'s own enumerable property names. @@ -1585,7 +1586,7 @@ _.max(stooges, function(stooge) { return stooge.age; }); ### `_.memoize(func [, resolver])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L2081 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L2111 "View in source") [Ⓣ][1] Creates a new function that memoizes the result of `func`. If `resolver` is passed, it will be used to determine the cache key for storing the result based on the arguments passed to the memoized function. By default, the first argument passed to the memoized function is used as the cache key. @@ -1637,7 +1638,7 @@ _.min([10, 5, 100, 2, 1000]); ### `_.mixin(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L3028 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L3058 "View in source") [Ⓣ][1] Adds functions properties of `object` to the `lodash` function and chainable wrapper. @@ -1667,7 +1668,7 @@ _('larry').capitalize(); ### `_.noConflict()` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L3059 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L3089 "View in source") [Ⓣ][1] Reverts the '_' variable to its previous value and returns a reference to the `lodash` function. @@ -1687,7 +1688,7 @@ var lodash = _.noConflict(); ### `_.once(func)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L2107 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L2137 "View in source") [Ⓣ][1] Creates a new function that is restricted to one execution. Repeat calls to the function will return the value of the first call. @@ -1713,7 +1714,7 @@ initialize(); ### `_.partial(func [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L2140 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L2170 "View in source") [Ⓣ][1] Creates a new function that, when called, invokes `func` with any additional `partial` arguments prepended to those passed to the partially applied function. This method is similar `bind`, except it does **not** alter the `this` binding. @@ -1740,7 +1741,7 @@ hi('moe'); ### `_.pick(object [, prop1, prop2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L2901 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L2931 "View in source") [Ⓣ][1] Creates an object composed of the specified properties. Property names may be specified as individual arguments or as arrays of property names. @@ -1941,7 +1942,7 @@ _.rest([3, 2, 1]); ### `_.result(object, property)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L3091 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L3121 "View in source") [Ⓣ][1] Resolves the value of `property` on `object`. If `property` is a function it will be invoked and its result returned, else the property value is returned. If `object` is falsey, then `null` is returned. @@ -2000,7 +2001,7 @@ _.shuffle([1, 2, 3, 4, 5, 6]); ### `_.size(value)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L2940 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L2970 "View in source") [Ⓣ][1] Gets the size of `value` by returning `value.length` if `value` is a string or array, or the number of own enumerable properties if `value` is an object. @@ -2129,7 +2130,7 @@ _.sortedIndex(['twenty', 'thirty', 'fourty'], 'thirty-five', function(word) { ### `_.tap(value, interceptor)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L3338 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L3368 "View in source") [Ⓣ][1] Invokes `interceptor` with the `value` as the first argument, and then returns `value`. The purpose of this method is to "tap into" a method chain, in order to perform operations on intermediate results within the chain. @@ -2159,7 +2160,7 @@ _.chain([1,2,3,200]) ### `_.template(text, data, options)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L3151 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L3181 "View in source") [Ⓣ][1] A micro-templating method that handles arbitrary delimiters, preserves whitespace, and correctly escapes quotes within interpolated code. @@ -2218,7 +2219,7 @@ _.template('<%= data.hasWith %>', { 'hasWith': 'no' }, { 'variable': 'data' }); ### `_.throttle(func, wait)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L2176 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L2206 "View in source") [Ⓣ][1] Creates a new function that, when executed, will only call the `func` function at most once per every `wait` milliseconds. If the throttled function is invoked more than once during the `wait` timeout, `func` will also be called on the trailing edge of the timeout. Subsequent calls to the throttled function will return the result of the last `func` call. @@ -2243,7 +2244,7 @@ jQuery(window).on('scroll', throttled); ### `_.times(n, callback [, thisArg])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L3254 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L3284 "View in source") [Ⓣ][1] Executes the `callback` function `n` times. The `callback` is bound to `thisArg` and invoked with `1` argument; *(index)*. @@ -2353,7 +2354,7 @@ _.uniq([1, 2, 1.5, 3, 2.5], function(num) { return this.floor(num); }, Math); ### `_.uniqueId([prefix])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L3281 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L3311 "View in source") [Ⓣ][1] Generates a unique id. If `prefix` is passed, the id will be appended to it. @@ -2377,7 +2378,7 @@ _.uniqueId('contact_'); ### `_.values(object)` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L2961 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L2991 "View in source") [Ⓣ][1] Produces an array of `object`'s own enumerable property values. @@ -2426,7 +2427,7 @@ _.without([1, 2, 1, 0, 3, 1, 4], 0, 1); ### `_.wrap(func, wrapper [, arg1, arg2, ...])` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L2228 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L2258 "View in source") [Ⓣ][1] Create a new function that passes the `func` function to the `wrapper` function as its first argument. Additional arguments are appended to those passed to the `wrapper` function. @@ -2458,7 +2459,7 @@ hello(); ### `_.zip([array1, array2, ...])` # [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L1769 "View in source") [Ⓣ][1] -Merges together the values of each of the arrays with the value at the corresponding position. Useful for separate data sources that are coordinated through matching array indexes. For a matrix of nested arrays, `_.zip.apply(...)` can transpose the matrix in a similar fashion. +Merges the elements of each array at their corresponding indexes. Useful for separate data sources that are coordinated through matching array indexes. For a matrix of nested arrays, `_.zip.apply(...)` can transpose the matrix in a similar fashion. #### Arguments 1. `[array1, array2, ...]` *(Array)*: Arrays to process. @@ -2477,6 +2478,30 @@ _.zip(['moe', 'larry', 'curly'], [30, 40, 50], [true, false, false]); + + +### `_.zipObject(keys)` +# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L1798 "View in source") [Ⓣ][1] + +Merges an array of `keys` and an array of `values` into a single object. + +#### Arguments +1. `keys` *(Array)*: The array of keys. + +#### Returns +*(Object)*: Returns an object composed of the given keys and corresponding values. + +#### Example +~~~ js +_.zipObject(['moe', 'larry', 'curly'], [30, 40, 50]); +// => { 'moe': 30, 'larry': 40, 'curly': 50 } +~~~ + +* * * + + + + @@ -2487,7 +2512,7 @@ _.zip(['moe', 'larry', 'curly'], [30, 40, 50], [true, false, false]); ### `_.prototype.chain()` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L3356 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L3386 "View in source") [Ⓣ][1] Enables method chaining on the wrapper object. @@ -2508,7 +2533,7 @@ _([1, 2, 3]).value(); ### `_.prototype.value()` -# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L3373 "View in source") [Ⓣ][1] +# [Ⓢ](https://github.com/bestiejs/lodash/blob/v0.3.2/lodash.js#L3403 "View in source") [Ⓣ][1] Extracts the wrapped value. diff --git a/lodash.js b/lodash.js index 4af4f17b4..3d5d6cb39 100644 --- a/lodash.js +++ b/lodash.js @@ -1751,10 +1751,10 @@ } /** - * Merges together the values of each of the arrays with the value at the - * corresponding position. Useful for separate data sources that are coordinated - * through matching array indexes. For a matrix of nested arrays, `_.zip.apply(...)` - * can transpose the matrix in a similar fashion. + * Merges the elements of each array at their corresponding indexes. Useful for + * separate data sources that are coordinated through matching array indexes. + * For a matrix of nested arrays, `_.zip.apply(...)` can transpose the matrix + * in a similar fashion. * * @static * @memberOf _ @@ -1780,6 +1780,36 @@ return result; } + /** + * Merges an array of `keys` and an array of `values` into a single object. + * + * @static + * @memberOf _ + * @category Arrays + * @param {Array} keys The array of keys. + * @param {Array} [values=[]] The array of values. + * @returns {Object} Returns an object composed of the given keys and + * corresponding values. + * @example + * + * _.zipObject(['moe', 'larry', 'curly'], [30, 40, 50]); + * // => { 'moe': 30, 'larry': 40, 'curly': 50 } + */ + function zipObject(keys, values) { + if (!keys) { + return {}; + } + var index = -1, + length = keys.length, + result = {}; + + values || (values = []); + while (++index < length) { + result[keys[index]] = values[index]; + } + return result; + } + /*--------------------------------------------------------------------------*/ /** @@ -3469,6 +3499,7 @@ lodash.without = without; lodash.wrap = wrap; lodash.zip = zip; + lodash.zipObject = zipObject; // assign aliases lodash.all = every; diff --git a/lodash.min.js b/lodash.min.js index 9d721168d..cf4ef1491 100644 --- a/lodash.min.js +++ b/lodash.min.js @@ -27,6 +27,6 @@ function(e){var t=[];if(!e)return t;for(var n,r=-1,i=e.length,s=tt.call(argument (Math.random()*(n+1)),i[n]=i[t],i[t]=e[n];return i},s.size=function(e){if(!e)return 0;var t=e.length;return t===t>>>0?e.length:Ot(e).length},s.some=ct,s.sortBy=mt,s.sortedIndex=x,s.tap=function(e,t){return t(e),e},s.template=function(e,t,n){n||(n={});var i,o,u=s.templateSettings,a=n.escape,c=n.evaluate,h=n.interpolate,n=n.variable;return a==r&&(a=u.escape),c==r&&(c=u.evaluate),h==r&&(h=u.interpolate),a&&(e=e.replace(a,d)),h&&(o=e!=(e=e.replace(h,v))),c&&(i=e!=(e=e.replace(c,m))),e="__p='"+e.replace (B,l).replace(P,f)+"';",I.length=0,n||(n=u.variable,e="with("+n+"||{}){"+e+"}"),e="function("+n+"){var __p"+(o?",__t":"")+(i?",__j=Array.prototype.join;function print(){__p+=__j.call(arguments,'')}":";")+e+"return __p}",i=Function("_","return "+e)(s),t?i(t):(i.source=e,i)},s.throttle=function(e,t){function n(){a=new Date,u=r,e.apply(o,i)}var i,s,o,u,a=0;return function(){var r=new Date,f=t-(r-a);return i=arguments,o=this,0>=f?(a=r,s=e.apply(o,i)):u||(u=at(n,f)),s}},s.times=function(e,t,n){var r=-1 ;if(n)for(;++r>>0?tt.call(e):Mt(e)},s.union=function(){for(var e=-1,t=[],n=Y.apply(t,arguments),r=n.length;++ew(t,n[e])&&t.push(n[e]);return t},s.uniq=T,s.uniqueId=function(e){var t=M++;return e?e+t:t},s.values=Mt,s.without=function(e){var t=[];if(!e)return t;for(var n=-1,r=e.length;++nw(arguments,e[n],1)&&t.push(e[n]);return t} -,s.wrap=function(e,t){return function(){var n=[e];return arguments.length&&et.apply(n,arguments),t.apply(this,n)}},s.zip=function(e){if(!e)return[];for(var t=-1,n=E(Tt(arguments,"length")),r=Array(n);++t