Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- let index = 0;
- let isEqual = false;
- for(let i = 0; i < input.length; i++){
- let leftSum = input.slice(0, --i).reduce((a, b) => a + b, 0);
- let rightSum = input.slice(++i).reduce((a, b) => a + b, 0);
- if(leftSum === rightSum){
- index = --i;
- isEqual = true;
- break;
- }
- }
- console.log(input.length === 1 || isEqual ? index : "no");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement