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,55 +21,77 @@ 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+ } from " @hetarth02/js-array-helpers" ;
2430
2531let arr = [1 , 2 ];
2632console .log (is_array (arr)); // true
2733
2834const objectX = {
29- 0 : " Apple" ,
30- 1 : " Microsoft" ,
31- 2 : " Google"
32- };
35+ 0 : " Apple" ,
36+ 1 : " Microsoft" ,
37+ 2 : " Google" ,
38+ };
3339console .log (object_to_array (objectX)); // ['Apple', 'Microsoft', 'Google']
3440
35- const mang = [' Microsoft' , ' apple' , ' netflix' , ' Google' ];
41+ const mang = [" Microsoft" , " apple" , " netflix" , " Google" ];
3642const result = search_in_array (" app" , mang);
3743console .log (result); // ['apple']
3844
3945// Santized array Example
4046
4147// Corrupted Data array with diff data types
4248const 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 }
49+ { name: " sam" , age: null , isEmployed: " false" },
50+ { name: " a " , age: 456 , isEmployed: false },
51+ { name: " c " , age: undefined , isEmployed: 00 } ,
52+ { name: null , age: 123 , isEmployed: true } ,
53+ { name: " asd" , age: 123 , isEmployed: false },
54+ { name: 00 , age: 123 , isEmployed: null } ,
55+ { name: " sam" , age: " 123" , isEmployed: undefined },
5056];
5157
5258// Given schema for correct data types
5359const my_schema = {
54- " name" : ' string' ,
55- " age" : ' number' ,
56- " isEmployed" : ' boolean'
60+ name: " string" ,
61+ age: " number" ,
62+ isEmployed: " boolean" ,
5763};
5864
5965// Run sanitize_array with array and schema
60- console .log (sanitize_array (my_array,my_schema));
66+ console .log (sanitize_array (my_array, my_schema));
6167
62- // Sanitized Output
68+ // Sanitized Output
6369// [ { name: 'sam', age: 0, isEmployed: false },
6470// { name: 'a', age: 456, isEmployed: false },
6571// { name: 'c', age: 0, isEmployed: true },
6672// { name: 'null', age: 123, isEmployed: true },
6773// { name: 'asd', age: 123, isEmployed: false },
6874// { name: '0', age: 123, isEmployed: false },
69- // { name: 'sam', age: 123, isEmployed: false }
75+ // { name: 'sam', age: 123, isEmployed: false }
7076// ]
7177
78+ // to reverse an array in parts
79+ let my_array = [1 , 2 , 3 , 4 , 5 ];
80+ let reverseInPart_array = array_reverse_part (my_array, 3 , 4 );
81+
82+ console .log (reverseInPart_array);
83+
84+ // output
85+ // rotated_array=[1,2,3,5,4];
86+
87+ // to rotate array counter clockwise
88+ let my_array1 = [1 , 2 , 3 , 4 , 5 ];
89+ let rotated_array = array_rotate (my_array1, 3 );
90+
91+ console .log (rotated_array);
92+
93+ // output
94+ // rotated_array=[4,5,1,2,3];
7295
7396// equilibrium_point program file execution
7497// Array = [1,3,5,2,2]
0 commit comments