Skip to content

Commit 119bd63

Browse files
committed
docs(array-utils): tweaks to docs and annotations
1 parent f936c78 commit 119bd63

File tree

7 files changed

+30
-0
lines changed

7 files changed

+30
-0
lines changed

packages/array-utils/src/flatten.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
/**
22
* Flatten the given array into a single array of elements.
3+
*
34
* The given array can be composed of multiple depths of objects and or arrays.
5+
*
46
* @param {Array} array - array to flatten
57
* @returns {Array} a flat array with a single list of elements
8+
*
69
* @alias module:array-utils.flatten
10+
* @function
11+
*
712
* @example
813
* const flat = flatten([[1], [2, 3, [4, 5]], 6]) // returns [1, 2, 3, 4, 5, 6]
914
*/

packages/array-utils/src/fnNumberSort.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
/**
22
* Compare function for sorting arrays of numbers.
3+
*
34
* @param {number} a - first number
45
* @param {number} b - second number
56
* @return {number} result of a - b
7+
*
68
* @alias module:array-utils.fnNumberSort
9+
* @function
10+
*
711
* @example
812
* const numbers = [2, 1, 4, 3, 6, 5, 8, 7, 9, 0]
913
* const sorted = numbers.sort(fnNumberSort)

packages/array-utils/src/head.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
/**
22
* Return the first element of the given array.
3+
*
34
* @param {*} array - anything
45
* @returns {*} first element of the array, or undefined
6+
*
57
* @alias module:array-utils.head
8+
* @function
9+
*
610
* @example
711
* let element = head([1, 2])
812
*/

packages/array-utils/src/insertSorted.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
/**
22
* Insert the given element into the give array using the compareFunction.
3+
*
34
* @param {Array} array - array in which to insert
45
* @param {*} element - element to insert into the array
56
* @param {Function} compareFunction - a function that defines the sort order of elements
7+
*
68
* @alias module:array-utils.insertSorted
9+
* @function
10+
*
711
* @example
812
* const numbers = [1, 5]
913
* const result = insertSorted(numbers, 3, fnNumberSort)

packages/array-utils/src/nth.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
/**
22
* Return the Nth element of the given array.
3+
*
34
* @param {*} array - anything
45
* @param {number} index - index of the element to return
56
* @returns {*} Nth element of the array, or undefined
7+
*
68
* @alias module:array-utils.nth
9+
* @function
10+
*
711
* @example
812
* let value = nth([1], 2) // undefined
913
* let value = nth([1, 2, 3, 4, 5], 3) // 4

packages/array-utils/src/padToLength.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
/**
22
* Build an array of the given target length from an existing array and a padding value.
3+
*
34
* If the array is already larger than the target length, it will not be shortened.
5+
*
46
* @param {Array} anArray - the source array to copy into the result.
57
* @param {*} padding - the value to add to the new array to reach the desired length.
68
* @param {number} targetLength - The desired length of the returned array.
79
* @returns {Array} an array with at least 'target length" elements
10+
*
811
* @alias module:array-utils.padToLength
12+
* @function
13+
*
914
* @example
1015
* const srcArray = [2, 3, 4]
1116
* const paddedArray = padToLength(srcArray, 0, 5)

packages/array-utils/src/toArray.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
/**
22
* Convert the given array to an array if not already an array.
3+
*
34
* @param {*} array - anything
45
* @returns {Array} an array
6+
*
57
* @alias module:array-utils.toArray
8+
* @function
9+
*
610
* @example
711
* const array = toArray(1) // [1]
812
*/

0 commit comments

Comments
 (0)