Skip to content

Commit 55168ad

Browse files
committed
Update index.js
1 parent d145e52 commit 55168ad

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

index.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
1-
//To throw error in case of invalid datatype.
1+
// To throw error in case of invalid datatype.
22
function _throw() {
33
throw new TypeError("Must be a valid array!");
44
}
55

6-
//To check if arr is array.
6+
// To check if arr is array.
77
function is_array(arr) {
88
return Array.isArray(arr) ? true : _throw();
99
}
1010

11-
//To get the head or first element of the array.
11+
// To get the head or first element of the array.
1212
function head(arr) {
1313
is_array(arr);
1414
return arr[0];
1515
}
1616

17-
//To get the tail last element of the array.
17+
// To get the tail last element of the array.
1818
function tail(arr) {
1919
is_array(arr);
2020
let element = arr.pop();
2121
arr.push(element);
2222
return element;
2323
}
2424

25-
//To check the existence of an element inside the array.
25+
// To check the existence of an element inside the array.
2626
function in_array(arr, value) {
2727
is_array(arr);
2828
return arr.includes(value);
2929
}
3030

31-
//To split arrays into fixed size chunks.
31+
// To split arrays into fixed size chunks.
3232
function array_chunk(arr, chunk_size) {
3333
is_array(arr);
3434
if (typeof chunk_size != "number") {
@@ -50,7 +50,7 @@ function array_chunk(arr, chunk_size) {
5050
}
5151
}
5252

53-
//To filter out arrays based on datatypes.
53+
// To filter out arrays based on datatypes.
5454
function array_filter(arr) {
5555
is_array(arr);
5656
arr = arr.filter((e) => {
@@ -59,7 +59,7 @@ function array_filter(arr) {
5959
return arr;
6060
}
6161

62-
//To get the frequency of occurence of each unique element inside the array.
62+
// To get the frequency of occurence of each unique element inside the array.
6363
function array_frequency(arr) {
6464
is_array(arr);
6565
let freq_obj = {};
@@ -73,19 +73,19 @@ function array_frequency(arr) {
7373
return freq_obj;
7474
}
7575

76-
//To convert Objects into Arrays.
76+
// To convert Objects into Arrays.
7777
function object_to_array(obj) {
7878
let temp = [];
7979
const entries = Object.entries(obj);
8080
entries.forEach((ent) => temp.push(ent[1]));
8181
return temp;
8282
}
8383

84-
//To get indexes of all occurences of an element inside an array.
84+
// To get indexes of all occurences of an element inside an array.
8585
function get_all_indexes(arr, val) {
8686
is_array(arr);
87-
var indexes = [], i;
88-
for(i = 0; i < arr.length; i++)
87+
var indexes = [];
88+
for(let i = 0; i < arr.length; i++)
8989
if (arr[i] === val)
9090
indexes.push(i);
9191
return indexes;

0 commit comments

Comments
 (0)