source: node_modules/es-toolkit/dist/compat/util/cond.js@ ba17441

Last change on this file since ba17441 was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago

Added visualizations

  • Property mode set to 100644
File size: 874 bytes
Line 
1'use strict';
2
3Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
5const iteratee = require('./iteratee.js');
6const isFunction = require('../../predicate/isFunction.js');
7
8function cond(pairs) {
9 const length = pairs.length;
10 const processedPairs = pairs.map(pair => {
11 const predicate = pair[0];
12 const func = pair[1];
13 if (!isFunction.isFunction(func)) {
14 throw new TypeError('Expected a function');
15 }
16 return [iteratee.iteratee(predicate), func];
17 });
18 return function (...args) {
19 for (let i = 0; i < length; i++) {
20 const pair = processedPairs[i];
21 const predicate = pair[0];
22 const func = pair[1];
23 if (predicate.apply(this, args)) {
24 return func.apply(this, args);
25 }
26 }
27 };
28}
29
30exports.cond = cond;
Note: See TracBrowser for help on using the repository browser.