Last active
March 31, 2023 06:22
-
-
Save sava-vidakovic/bbb2ab432d7ac6b512c210aca4c238cc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Equal Sides Of An Array | |
| function findEvenIndex(arr) { | |
| var sum = 0, | |
| leftSum = 0; | |
| for (var i = 0; i < arr.length; i++) { | |
| sum += arr[i]; | |
| } | |
| for (var i = 0; i < arr.length; i++) { | |
| sum -= arr[i]; | |
| if (leftSum === sum) { | |
| return i; | |
| } | |
| leftSum += arr[i]; | |
| } | |
| return -1; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's a working version of it