123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- var apply = require('./_apply'),
- arrayMap = require('./_arrayMap'),
- baseIteratee = require('./_baseIteratee'),
- baseRest = require('./_baseRest');
- var FUNC_ERROR_TEXT = 'Expected a function';
- function cond(pairs) {
- var length = pairs == null ? 0 : pairs.length,
- toIteratee = baseIteratee;
- pairs = !length ? [] : arrayMap(pairs, function(pair) {
- if (typeof pair[1] != 'function') {
- throw new TypeError(FUNC_ERROR_TEXT);
- }
- return [toIteratee(pair[0]), pair[1]];
- });
- return baseRest(function(args) {
- var index = -1;
- while (++index < length) {
- var pair = pairs[index];
- if (apply(pair[0], this, args)) {
- return apply(pair[1], this, args);
- }
- }
- });
- }
- module.exports = cond;
|