Skip to content

Commit b9b3ed5

Browse files
authored
Merge branch 'main' into adding-get-rms-value-function
2 parents 5a87142 + 8dcd7a3 commit b9b3ed5

File tree

2 files changed

+320
-188
lines changed

2 files changed

+320
-188
lines changed

README.md

Lines changed: 50 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# js-array-helpers
2+
23
![npm (scoped)](https://img.shields.io/npm/v/@hetarth02/js-array-helpers?style=for-the-badge)
34

45
Array 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,56 +21,61 @@ 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, get_rms_value } 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

2532
let arr = [1, 2];
2633
console.log(is_array(arr)); // true
2734

2835
const objectX = {
29-
0: "Apple",
30-
1: "Microsoft",
31-
2: "Google"
32-
};
36+
0: "Apple",
37+
1: "Microsoft",
38+
2: "Google",
39+
};
3340
console.log(object_to_array(objectX)); // ['Apple', 'Microsoft', 'Google']
3441

35-
const mang = ['Microsoft', 'apple', 'netflix', 'Google'];
42+
const mang = ["Microsoft", "apple", "netflix", "Google"];
3643
const result = search_in_array("app", mang);
3744
console.log(result); // ['apple']
3845

3946
// Santized array Example
4047

4148
// Corrupted Data array with diff data types
4249
const 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
5360
const 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

72-
7379
// get_rms_value example
7480

7581
// Given array of numbers
@@ -81,4 +87,26 @@ console.log(get_rms_value(values))
8187
// Calculated Root Mean Square value
8288
// 35.61834733205159
8389

84-
```
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
112+
```

0 commit comments

Comments
 (0)