Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function oddEvenPosition(n) {
- let sum1 = 0;
- let sum2 = 0;
- let max = Number.NEGATIVE_INFINITY;
- let min = Number.POSITIVE_INFINITY;
- let max2 = Number.NEGATIVE_INFINITY;
- let min2 = Number.POSITIVE_INFINITY;
- for (var i = 1; i < n.length; i++) {
- let currentNumber = Number(n[i]);
- if (i % 2 != 0) {
- if (currentNumber < min) {
- min = currentNumber;
- }
- if (currentNumber > max) {
- max = currentNumber;
- }
- sum1 += currentNumber;
- }
- if (i % 2 == 0) {
- if (currentNumber < min2) {
- min2 = currentNumber;
- }
- if (currentNumber > max2) {
- max2 = currentNumber;
- }
- sum2 += currentNumber;
- }
- }
- if (max === Number.NEGATIVE_INFINITY) {
- max = 'No';
- }
- if (min === Number.POSITIVE_INFINITY) {
- min = 'No';
- }
- if (max2 === Number.NEGATIVE_INFINITY) {
- max2 = 'No';
- }
- if (min2 === Number.POSITIVE_INFINITY) {
- min2 = 'No';
- }
- console.log(`OddSum=${sum1},
- OddMin=${min},
- OddMax=${max},
- EvenSum=${sum2},
- EvenMin=${min2},
- EvenMax=${max2}`);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement