source: node_modules/es-toolkit/dist/compat/array/partition.js

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

Added visualizations

  • Property mode set to 100644
File size: 845 bytes
Line 
1'use strict';
2
3Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
5const identity = require('../../function/identity.js');
6const isArrayLike = require('../predicate/isArrayLike.js');
7const iteratee = require('../util/iteratee.js');
8
9function partition(source, predicate = identity.identity) {
10 if (!source) {
11 return [[], []];
12 }
13 const collection = isArrayLike.isArrayLike(source) ? source : Object.values(source);
14 predicate = iteratee.iteratee(predicate);
15 const matched = [];
16 const unmatched = [];
17 for (let i = 0; i < collection.length; i++) {
18 const value = collection[i];
19 if (predicate(value)) {
20 matched.push(value);
21 }
22 else {
23 unmatched.push(value);
24 }
25 }
26 return [matched, unmatched];
27}
28
29exports.partition = partition;
Note: See TracBrowser for help on using the repository browser.