File tree Expand file tree Collapse file tree 1 file changed +13
-2
lines changed
Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Original file line number Diff line number Diff 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.
5454function 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.
7777function 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+
8494export {
8595 head ,
8696 tail ,
@@ -90,4 +100,5 @@ export {
90100 array_filter ,
91101 array_frequency ,
92102 object_to_array ,
103+ get_all_indexes ,
93104} ;
You can’t perform that action at this time.
0 commit comments