mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-02 16:17:50 +00:00
Add _.cond doc example. [ci skip]
This commit is contained in:
15
lodash.js
15
lodash.js
@@ -12832,6 +12832,21 @@
|
||||
* @param {Array} pairs The predicate-function pairs.
|
||||
* @returns {Function} Returns the new function.
|
||||
* @example
|
||||
*
|
||||
* var func = _.cond([
|
||||
* [_.matches({ 'a': 1 }), _.constant('matches A')],
|
||||
* [_.conforms({ 'b': _.isNumber }), _.constant('matches B')],
|
||||
* [_.constant(true), _.constant('no match')]
|
||||
* ])
|
||||
*
|
||||
* func({ 'a': 1, 'b': 2 });
|
||||
* // => 'matches A'
|
||||
*
|
||||
* func({ 'a': 0, 'b': 1 });
|
||||
* // => 'matches B'
|
||||
*
|
||||
* func({ 'a': '1', 'b': '2' });
|
||||
* // => 'no match'
|
||||
*/
|
||||
function cond(pairs) {
|
||||
var length = pairs ? pairs.length : 0,
|
||||
|
||||
Reference in New Issue
Block a user