Skip to content

Commit 02f24fa

Browse files
authored
Merge pull request #25 from Jimmy-Taravia2001/main
equilibrium_point__Programme_added
2 parents dbab3c4 + fbf0b8f commit 02f24fa

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,9 @@ console.log(sanitize_array(my_array,my_schema));
6969
// { name: 'sam', age: 123, isEmployed: false }
7070
// ]
7171

72+
73+
//equilibrium_point program file execution
74+
// Array = [1,3,5,2,2]
75+
//n=5
76+
//output = 3
7277
```

index.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,44 @@ function get_only(arr, keys) {
353353
);
354354
}
355355

356+
357+
/**
358+
* Get the equilibrium point of an array which means the array element position where the
359+
* sum of elements on left side and sum of element on right side of that element in array are same.
360+
*
361+
*
362+
* @param array a
363+
* @param number n
364+
* @returns number
365+
*/
366+
367+
function equilibrium_Point(a, n){
368+
is_array(a);
369+
let i=0;
370+
let j=n-1;
371+
let s1=0;
372+
let s2=0;
373+
while(i<j){
374+
if(s1<=s2){
375+
s1=s1+a[i];
376+
i++;
377+
}
378+
else{
379+
s2=s2+a[j];
380+
j--;
381+
}
382+
}
383+
384+
if(s1==s2){
385+
return i+1;
386+
}
387+
else{
388+
return -1;
389+
}
390+
391+
}
392+
393+
356394
export {
357395
is_array,
358396
is_num_array,
@@ -374,4 +412,5 @@ export {
374412
difference,
375413
sanitize_array,
376414
get_only,
415+
equilibrium_Point,
377416
};

0 commit comments

Comments
 (0)