source: node_modules/es-toolkit/dist/compat/util/cond.mjs

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

Added visualizations

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