Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function leftAndRightSum(input) {
- let num = parseInt(input[0]);
- let leftSum = 0;
- let rightSum = 0;
- for (let i = 1; i <= num * 2; i++) {
- if (i <= num){
- leftSum += parseInt(input[i]);
- }
- else{
- rightSum += parseInt(input[i]);
- }
- }
- if (leftSum === rightSum) {
- console.log(`Yes, sum = ${leftSum}`);
- } else {
- console.log(`No, diff = ${Math.abs(leftSum - rightSum)}`);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement