Skip to content

Commit 902ee2f

Browse files
authored
Merge pull request #14 from igrzhukovich/feature/update-docs
feature: update docs of function to JSDOC format Closes #12 #hacktoberfest
2 parents 631d3b6 + 8a1f350 commit 902ee2f

File tree

1 file changed

+79
-12
lines changed

1 file changed

+79
-12
lines changed

index.js

Lines changed: 79 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ function is_array(arr) {
1717
return Array.isArray(arr) ? true : _throw();
1818
}
1919

20-
// To check if arr has only nums.
20+
/**
21+
* To check if array of numbers.
22+
*
23+
* @param array arr
24+
* @returns bool | TypeError
25+
*/
2126
function is_num_array(arr) {
2227
var a = arr.reduce(function (result, val) {
2328
return result && typeof val === "number";
@@ -27,27 +32,49 @@ function is_num_array(arr) {
2732
}
2833
}
2934

30-
// To get the head or first element of the array.
35+
/**
36+
* To get the head or first element of the array.
37+
*
38+
* @param array arr
39+
* @returns any
40+
*/
3141
function head(arr) {
3242
is_array(arr);
3343
return arr[0];
3444
}
3545

36-
// To get the tail last element of the array.
46+
/**
47+
* To get the tail last element of the array.
48+
*
49+
* @param array arr
50+
* @returns any
51+
*/
3752
function tail(arr) {
3853
is_array(arr);
3954
let element = arr.pop();
4055
arr.push(element);
4156
return element;
4257
}
4358

44-
// To check the existence of an element inside the array.
59+
/**
60+
* To check the existence of an element inside the array.
61+
*
62+
* @param array arr
63+
* @param any value
64+
* @returns any
65+
*/
4566
function in_array(arr, value) {
4667
is_array(arr);
4768
return arr.includes(value);
4869
}
4970

50-
// To split arrays into fixed size chunks.
71+
/**
72+
* To split arrays into fixed size chunks.
73+
*
74+
* @param array arr
75+
* @param number chunk_size
76+
* @returns any
77+
*/
5178
function array_chunk(arr, chunk_size) {
5279
is_array(arr);
5380
if (typeof chunk_size != "number") {
@@ -69,7 +96,12 @@ function array_chunk(arr, chunk_size) {
6996
}
7097
}
7198

72-
// To filter out arrays by removing nullish values.
99+
/**
100+
* To filter out arrays by removing nullish values.
101+
*
102+
* @param array arr
103+
* @returns array
104+
*/
73105
function array_filter(arr) {
74106
is_array(arr);
75107
arr = arr.filter((e) => {
@@ -78,7 +110,12 @@ function array_filter(arr) {
78110
return arr;
79111
}
80112

81-
// To get the frequency of occurence of each unique element inside the array.
113+
/**
114+
* To get the frequency of occurence of each unique element inside the array.
115+
*
116+
* @param array arr
117+
* @returns array
118+
*/
82119
function array_frequency(arr) {
83120
is_array(arr);
84121
let freq_obj = {};
@@ -92,15 +129,26 @@ function array_frequency(arr) {
92129
return freq_obj;
93130
}
94131

95-
// To convert Objects into Arrays.
132+
/**
133+
* To convert Objects into Arrays.
134+
*
135+
* @param object obj
136+
* @returns array
137+
*/
96138
function object_to_array(obj) {
97139
let temp = [];
98140
const entries = Object.entries(obj);
99141
entries.forEach((ent) => temp.push(ent[1]));
100142
return temp;
101143
}
102144

103-
// To get indexes of all occurences of an element inside an array.
145+
/**
146+
* To get indexes of all occurences of an element inside an array.
147+
*
148+
* @param array arr
149+
* @param any val
150+
* @returns array
151+
*/
104152
function get_all_indexes(arr, val) {
105153
is_array(arr);
106154
var indexes = [];
@@ -112,21 +160,40 @@ function get_all_indexes(arr, val) {
112160
return indexes;
113161
}
114162

115-
// To check if a substr exists within an array of strings
163+
/**
164+
* To check if a substr exists within an array of strings
165+
*
166+
* @param string query
167+
* @param array arr
168+
* @returns array
169+
*/
116170
function search_in_array(query, arr) {
117171
is_array(arr);
118172
return arr.filter(
119173
(item) => item.toLowerCase().search(query.toLowerCase()) !== -1
120174
);
121175
}
122176

123-
// Get sum of array
177+
/**
178+
* Get sum of array
179+
*
180+
* @param array arr
181+
* @returns number
182+
*/
124183
function array_sum(arr) {
125184
is_array(arr);
126185
return arr.reduce((prev, curr) => (isNaN(curr) ? 0 : prev + curr), 0);
127186
}
128187

129-
// Get sum of a subarray
188+
/**
189+
* Get sum of a subarray
190+
*
191+
* @param array arr
192+
* @param number slice_start
193+
* @param number slice_end
194+
* @param bool includes
195+
* @returns number | TypeError
196+
*/
130197
function array_slice_sum(
131198
arr,
132199
slice_start = 0,

0 commit comments

Comments
 (0)