Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function oddEvenPosition(input) {
- let n = parseInt(input[0]);
- let oddMin = Number.MAX_VALUE;
- let oddMax = -Number.MAX_VALUE;
- let oddSum = 0;
- let evenMin = Number.MAX_VALUE;
- let evenMax = -Number.MAX_VALUE;
- let evenSum = 0;
- for (let i = 1; i <= n; i++) {
- let currentNum = parseFloat(input[i]);
- if (i % 2 === 1) {
- oddSum += currentNum;
- if (currentNum < oddMin) {
- oddMin = currentNum;
- }
- if (currentNum > oddMax) {
- oddMax = currentNum;
- }
- } else {
- evenSum += currentNum;
- if (currentNum < evenMin) {
- evenMin = currentNum;
- }
- if (currentNum > evenMax) {
- evenMax = currentNum;
- }
- }
- }
- if (n === 0) {
- console.log("OddSum=0.00,\nOddMin=No,\nOddMax=No,");
- } else {
- console.log(`OddSum=${oddSum.toFixed(2)},\nOddMin=${oddMin.toFixed(2)},\nOddMax=${oddMax.toFixed(2)},`);
- }
- if (n <= 1) {
- console.log("EvenSum=0.00,\nEvenMin=No,\nEvenMax=No");
- } else {
- console.log(`EvenSum=${evenSum.toFixed(2)},\nEvenMin=${evenMin.toFixed(2)},\nEvenMax=${evenMax.toFixed(2)}`);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement