From 967ce824f7c925e0e1002ec61eb36ff72bc2a19e Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Tue, 9 Sep 2014 23:32:06 -0700 Subject: [PATCH] Add `_.thru` doc example and add `pattern` param to `_.words`. [ci skip] --- lodash.js | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/lodash.js b/lodash.js index 4f577f934..e4cbf1e5b 100644 --- a/lodash.js +++ b/lodash.js @@ -4485,11 +4485,11 @@ * @returns {*} Returns `value`. * @example * - * _([1, 2, 3, 4]) + * _([1, 2, 3]) * .tap(function(array) { array.pop(); }) * .reverse() * .value(); - * // => [3, 2, 1] + * // => [2, 1] */ function tap(value, interceptor, thisArg) { interceptor.call(thisArg, value); @@ -4507,6 +4507,12 @@ * @param {*} [thisArg] The `this` binding of `interceptor`. * @returns {*} Returns the result of `interceptor`. * @example + * + * _([1, 2, 3]) + * .last() + * .thru(function(value) { return [value]; }) + * .value(); + * // => [3] */ function thru(value, interceptor, thisArg) { return interceptor.call(thisArg, value); @@ -8756,15 +8762,19 @@ * @memberOf _ * @category String * @param {string} [string=''] The string to inspect. + * @param {RegExp|string} [pattern] The pattern to match words. * @returns {Array} Returns the words of `string`. * @example * - * _.words('hello world'); - * // => ['hello', 'world'] + * _.words('fred, barney, & pebbles'); + * // => ['fred', 'barney', 'pebbles'] + * + * _.words('fred, barney, & pebbles', /[^, ]+/g); + * // => ['fred', 'barney', '&', 'pebbles'] */ - function words(string) { + function words(string, pattern) { string = string == null ? '' : String(string); - return (string && string.match(reWords)) || []; + return (string && string.match(pattern || reWords)) || []; } /*------------------------------------------------------------------------*/