Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(array) {
- let arr = array
- let arrL = array.length
- let sumLeft = 0
- let sumRight = 0
- let equalSumsFound = false;
- let i = 0
- for (i = 0; i < arrL; i++) {
- sumLeft = 0
- sumRight = 0
- for (j = i - 1; j >= 0; j--) {
- sumLeft += arr[j]
- }
- for (k = i + 1; k < arrL; k++) {
- sumRight += arr[k]
- }
- if (sumLeft == sumRight) {
- console.log(i)
- break
- }
- }
- if (sumLeft !== sumRight) {
- console.log("no")
- }
- }
Add Comment
Please, Sign In to add comment