|
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:
717 bytes
|
| Line | |
|---|
| 1 | import { identity } from '../../function/identity.mjs';
|
|---|
| 2 | import { isArrayLike } from '../predicate/isArrayLike.mjs';
|
|---|
| 3 | import { iteratee } from '../util/iteratee.mjs';
|
|---|
| 4 |
|
|---|
| 5 | function partition(source, predicate = identity) {
|
|---|
| 6 | if (!source) {
|
|---|
| 7 | return [[], []];
|
|---|
| 8 | }
|
|---|
| 9 | const collection = isArrayLike(source) ? source : Object.values(source);
|
|---|
| 10 | predicate = iteratee(predicate);
|
|---|
| 11 | const matched = [];
|
|---|
| 12 | const unmatched = [];
|
|---|
| 13 | for (let i = 0; i < collection.length; i++) {
|
|---|
| 14 | const value = collection[i];
|
|---|
| 15 | if (predicate(value)) {
|
|---|
| 16 | matched.push(value);
|
|---|
| 17 | }
|
|---|
| 18 | else {
|
|---|
| 19 | unmatched.push(value);
|
|---|
| 20 | }
|
|---|
| 21 | }
|
|---|
| 22 | return [matched, unmatched];
|
|---|
| 23 | }
|
|---|
| 24 |
|
|---|
| 25 | export { partition };
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.