Skip to content

Commit d145e52

Browse files
committed
Update index.js
get_all_indexes Function added
1 parent 1cb709d commit d145e52

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

index.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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) => {
@@ -73,14 +73,24 @@ 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.
85+
function get_all_indexes(arr, val) {
86+
is_array(arr);
87+
var indexes = [], i;
88+
for(i = 0; i < arr.length; i++)
89+
if (arr[i] === val)
90+
indexes.push(i);
91+
return indexes;
92+
}
93+
8494
export {
8595
head,
8696
tail,
@@ -90,4 +100,5 @@ export {
90100
array_filter,
91101
array_frequency,
92102
object_to_array,
103+
get_all_indexes,
93104
};

0 commit comments

Comments
 (0)