es-toolkit 1.50.0-dev.1984 → 1.50.0-dev.1985
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -8,7 +8,7 @@ const require_iteratee = require("../util/iteratee.js");
|
|
|
8
8
|
* `predicate` returns falsy for. The predicate is invoked with one argument: (value).
|
|
9
9
|
*
|
|
10
10
|
* @template T
|
|
11
|
-
* @param
|
|
11
|
+
* @param collection - The array or object to iterate over.
|
|
12
12
|
* @param [predicate=identity] - The function invoked per iteration.
|
|
13
13
|
* @returns Returns the array of grouped elements.
|
|
14
14
|
*
|
|
@@ -25,14 +25,14 @@ const require_iteratee = require("../util/iteratee.js");
|
|
|
25
25
|
* partition([{ a: 1 }, { a: 2 }, { a: 3 }], ['a', 2]);
|
|
26
26
|
* // => [[{ a: 2 }], [{ a: 1 }, { a: 3 }]]
|
|
27
27
|
*/
|
|
28
|
-
function partition(
|
|
29
|
-
if (!
|
|
30
|
-
const
|
|
28
|
+
function partition(collection, predicate = require_identity.identity) {
|
|
29
|
+
if (!collection) return [[], []];
|
|
30
|
+
const values = require_isArrayLike.isArrayLike(collection) ? collection : Object.values(collection);
|
|
31
31
|
predicate = require_iteratee.iteratee(predicate);
|
|
32
32
|
const matched = [];
|
|
33
33
|
const unmatched = [];
|
|
34
|
-
for (let i = 0; i <
|
|
35
|
-
const value =
|
|
34
|
+
for (let i = 0; i < values.length; i++) {
|
|
35
|
+
const value = values[i];
|
|
36
36
|
if (predicate(value)) matched.push(value);
|
|
37
37
|
else unmatched.push(value);
|
|
38
38
|
}
|
|
@@ -8,7 +8,7 @@ import { iteratee } from "../util/iteratee.mjs";
|
|
|
8
8
|
* `predicate` returns falsy for. The predicate is invoked with one argument: (value).
|
|
9
9
|
*
|
|
10
10
|
* @template T
|
|
11
|
-
* @param
|
|
11
|
+
* @param collection - The array or object to iterate over.
|
|
12
12
|
* @param [predicate=identity] - The function invoked per iteration.
|
|
13
13
|
* @returns Returns the array of grouped elements.
|
|
14
14
|
*
|
|
@@ -25,14 +25,14 @@ import { iteratee } from "../util/iteratee.mjs";
|
|
|
25
25
|
* partition([{ a: 1 }, { a: 2 }, { a: 3 }], ['a', 2]);
|
|
26
26
|
* // => [[{ a: 2 }], [{ a: 1 }, { a: 3 }]]
|
|
27
27
|
*/
|
|
28
|
-
function partition(
|
|
29
|
-
if (!
|
|
30
|
-
const
|
|
28
|
+
function partition(collection, predicate = identity) {
|
|
29
|
+
if (!collection) return [[], []];
|
|
30
|
+
const values = isArrayLike(collection) ? collection : Object.values(collection);
|
|
31
31
|
predicate = iteratee(predicate);
|
|
32
32
|
const matched = [];
|
|
33
33
|
const unmatched = [];
|
|
34
|
-
for (let i = 0; i <
|
|
35
|
-
const value =
|
|
34
|
+
for (let i = 0; i < values.length; i++) {
|
|
35
|
+
const value = values[i];
|
|
36
36
|
if (predicate(value)) matched.push(value);
|
|
37
37
|
else unmatched.push(value);
|
|
38
38
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "es-toolkit",
|
|
3
|
-
"version": "1.50.0-dev.
|
|
3
|
+
"version": "1.50.0-dev.1985+89d9f820",
|
|
4
4
|
"description": "A state-of-the-art, high-performance JavaScript utility library with a small bundle size and strong type annotations.",
|
|
5
5
|
"homepage": "https://es-toolkit.dev",
|
|
6
6
|
"bugs": "https://github.com/toss/es-toolkit/issues",
|