|
Last change
on this file since a762898 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 |
|
|---|
| 3 | Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|---|
| 4 |
|
|---|
| 5 | const iteratee = require('./iteratee.js');
|
|---|
| 6 | const isFunction = require('../../predicate/isFunction.js');
|
|---|
| 7 |
|
|---|
| 8 | function 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 |
|
|---|
| 30 | exports.cond = cond;
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.