11# js-array-helpers
2+
23![ npm (scoped)] ( https://img.shields.io/npm/v/@hetarth02/js-array-helpers?style=for-the-badge )
34
45Array Helper functions for your quick use.
@@ -11,7 +12,7 @@ npm i @hetarth02/js-array-helpers
1112
1213# Contributing
1314
14- - To conttribute please refer [ CONTRIBUTING.md] ( CONTRIBUTING.md ) .
15+ - To conttribute please refer [ CONTRIBUTING.md] ( CONTRIBUTING.md ) .
1516
1617# How to use
1718
@@ -20,53 +21,92 @@ In your `package.json` add the following, `"type": "module"`.
2021# Example Usage
2122
2223``` js
23- import { is_array , object_to_array , search_in_array ,sanitize_array } from " @hetarth02/js-array-helpers" ;
24+ import {
25+ is_array ,
26+ object_to_array ,
27+ search_in_array ,
28+ sanitize_array ,
29+ get_rms_value ,
30+ } from " @hetarth02/js-array-helpers" ;
2431
2532let arr = [1 , 2 ];
2633console .log (is_array (arr)); // true
2734
2835const objectX = {
29- 0 : " Apple" ,
30- 1 : " Microsoft" ,
31- 2 : " Google"
32- };
36+ 0 : " Apple" ,
37+ 1 : " Microsoft" ,
38+ 2 : " Google" ,
39+ };
3340console .log (object_to_array (objectX)); // ['Apple', 'Microsoft', 'Google']
3441
35- const mang = [' Microsoft' , ' apple' , ' netflix' , ' Google' ];
42+ const mang = [" Microsoft" , " apple" , " netflix" , " Google" ];
3643const result = search_in_array (" app" , mang);
3744console .log (result); // ['apple']
3845
3946// Santized array Example
4047
4148// Corrupted Data array with diff data types
4249const my_array = [
43- { name: ' sam' , age: null , isEmployed: ' false' },
44- { name: ' a ' , age: 456 , isEmployed: false },
45- { name: ' c ' , age: undefined , isEmployed: 00 } ,
46- { name: null , age: 123 , isEmployed: true } ,
47- { name: ' asd' , age: 123 , isEmployed: false } ,
48- { name: 00 , age: 123 , isEmployed: null } ,
49- { name: ' sam' , age: ' 123' , isEmployed: undefined }
50+ { name: " sam" , age: null , isEmployed: " false" },
51+ { name: " a " , age: 456 , isEmployed: false },
52+ { name: " c " , age: undefined , isEmployed: 00 } ,
53+ { name: null , age: 123 , isEmployed: true } ,
54+ { name: " asd" , age: 123 , isEmployed: false },
55+ { name: 00 , age: 123 , isEmployed: null } ,
56+ { name: " sam" , age: " 123" , isEmployed: undefined },
5057];
5158
5259// Given schema for correct data types
5360const my_schema = {
54- " name" : ' string' ,
55- " age" : ' number' ,
56- " isEmployed" : ' boolean'
61+ name: " string" ,
62+ age: " number" ,
63+ isEmployed: " boolean" ,
5764};
5865
5966// Run sanitize_array with array and schema
60- console .log (sanitize_array (my_array,my_schema));
67+ console .log (sanitize_array (my_array, my_schema));
6168
62- // Sanitized Output
69+ // Sanitized Output
6370// [ { name: 'sam', age: 0, isEmployed: false },
6471// { name: 'a', age: 456, isEmployed: false },
6572// { name: 'c', age: 0, isEmployed: true },
6673// { name: 'null', age: 123, isEmployed: true },
6774// { name: 'asd', age: 123, isEmployed: false },
6875// { name: '0', age: 123, isEmployed: false },
69- // { name: 'sam', age: 123, isEmployed: false }
76+ // { name: 'sam', age: 123, isEmployed: false }
7077// ]
7178
79+ // get_rms_value example
80+
81+ // Given array of numbers
82+ const values = [23 , 54 , 19 ];
83+
84+ // Run get_rms_value with array
85+ console .log (get_rms_value (values))
86+
87+ // Calculated Root Mean Square value
88+ // 35.61834733205159
89+
90+ // to reverse an array in parts
91+ let my_array = [1 , 2 , 3 , 4 , 5 ];
92+ let reverseInPart_array = array_reverse_part (my_array, 3 , 4 );
93+
94+ console .log (reverseInPart_array);
95+
96+ // output
97+ // rotated_array=[1,2,3,5,4];
98+
99+ // to rotate array counter clockwise
100+ let my_array1 = [1 , 2 , 3 , 4 , 5 ];
101+ let rotated_array = array_rotate (my_array1, 3 );
102+
103+ console .log (rotated_array);
104+
105+ // output
106+ // rotated_array=[4,5,1,2,3];
107+
108+ // equilibrium_point program file execution
109+ // Array = [1,3,5,2,2]
110+ // n=5
111+ // output = 3
72112```
0 commit comments