Skip to content

Commit 5a3760e

Browse files
committed
docs(util): added jsdoc annotations for ArrayHelpers.js
1 parent 46e8639 commit 5a3760e

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

lib/util/ArrayHelpers.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@
55

66
"use strict";
77

8+
/**
9+
* Compare two arrays or strings by performing strict equality check for each value.
10+
* @template T [T=any]
11+
* @param {ArrayLike<T>} a Array of values to be compared
12+
* @param {ArrayLike<T>} b Array of values to be compared
13+
* @returns {boolean} returns true if all the elements of passed arrays are strictly equal.
14+
*/
15+
816
exports.equals = (a, b) => {
917
if (a.length !== b.length) return false;
1018
for (let i = 0; i < a.length; i++) {
@@ -14,13 +22,19 @@ exports.equals = (a, b) => {
1422
};
1523

1624
/**
17-
*
18-
* @param {Array} arr Array of values to be partitioned
19-
* @param {(value: any) => boolean} fn Partition function which partitions based on truthiness of result.
20-
* @returns {[Array, Array]} returns the values of `arr` partitioned into two new arrays based on fn predicate.
25+
* Partition an array by calling a predicate function on each value.
26+
* @template T [T=any]
27+
* @param {Array<T>} arr Array of values to be partitioned
28+
* @param {(value: T) => boolean} fn Partition function which partitions based on truthiness of result.
29+
* @returns {[Array<T>, Array<T>]} returns the values of `arr` partitioned into two new arrays based on fn predicate.
2130
*/
2231
exports.groupBy = (arr = [], fn) => {
2332
return arr.reduce(
33+
/**
34+
* @param {[Array<T>, Array<T>]} groups An accumulator storing already partitioned values returned from previous call.
35+
* @param {T} value The value of the current element
36+
* @returns {[Array<T>, Array<T>]} returns an array of partitioned groups accumulator resulting from calling a predicate on the current value.
37+
*/
2438
(groups, value) => {
2539
groups[fn(value) ? 0 : 1].push(value);
2640
return groups;

0 commit comments

Comments
 (0)