Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(array) {
- function equalSum(array) {
- if(array.length===1){
- return 0;
- }
- let right_sum = 0;
- let left_sum = 0;
- for (let i = 1; i < array.length; i++) {
- right_sum += array[i];
- }
- for (let i = 0, j = 1; j < array.length; i++, j++) {
- right_sum -= array[j];
- left_sum += array[i];
- if (left_sum === right_sum) {
- return i+1;
- }
- }
- return "no";
- }
- console.log(equalSum(array));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement