SHARE
TWEET

06. Equal Sums

igelov Jun 6th, 2020 (edited) 748 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(array) {
  2.     function equalSum(array) {
  3.         if(array.length===1){
  4.             return 0;
  5.         }
  6.         let right_sum = 0;
  7.         let left_sum = 0;
  8.         for (let i = 1; i < array.length; i++) {
  9.             right_sum += array[i];
  10.         }
  11.         for (let    i = 0, j = 1; j < array.length; i++, j++) {
  12.             right_sum -= array[j];
  13.             left_sum += array[i];
  14.             if (left_sum === right_sum) {
  15.                 return i+1;
  16.             }
  17.         }
  18.         return "no";
  19.     }
  20.  
  21.     console.log(equalSum(array));
  22. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top