vikkktor

Arrays_equalSums

Oct 4th, 2021 (edited)
948
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(array) {
  2.     let arr = array
  3.     let arrL = array.length
  4.     let sumLeft = 0
  5.     let sumRight = 0
  6.     let equalSumsFound = false;
  7.     let i = 0
  8.  
  9.     for (i = 0; i < arrL; i++) {
  10.         sumLeft = 0
  11.         sumRight = 0
  12.  
  13.         for (j = i - 1; j >= 0; j--) {
  14.             sumLeft += arr[j]
  15.         }
  16.  
  17.         for (k = i + 1; k < arrL; k++) {
  18.             sumRight += arr[k]
  19.         }
  20.  
  21.         if (sumLeft == sumRight) {
  22.             console.log(i)
  23.             break
  24.         }
  25.     }
  26.     if (sumLeft !== sumRight) {
  27.         console.log("no")
  28.     }
  29.  
  30. }
RAW Paste Data