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