Advertisement
Guest User

Untitled

a guest
Aug 31st, 2017
396
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. function oddEvenPosition(n) {
  2. let sum1 = 0;
  3. let sum2 = 0;
  4. let max = Number.NEGATIVE_INFINITY;
  5. let min = Number.POSITIVE_INFINITY;
  6. let max2 = Number.NEGATIVE_INFINITY;
  7. let min2 = Number.POSITIVE_INFINITY;
  8.  
  9. for (var i = 1; i < n.length; i++) {
  10. let currentNumber = Number(n[i]);
  11. if (i % 2 != 0) {
  12.  
  13.  
  14. if (currentNumber < min) {
  15. min = currentNumber;
  16. }
  17. if (currentNumber > max) {
  18. max = currentNumber;
  19. }
  20.  
  21. sum1 += currentNumber;
  22. }
  23. if (i % 2 == 0) {
  24.  
  25.  
  26. if (currentNumber < min2) {
  27. min2 = currentNumber;
  28. }
  29. if (currentNumber > max2) {
  30. max2 = currentNumber;
  31. }
  32. sum2 += currentNumber;
  33. }
  34. }
  35. if (max === Number.NEGATIVE_INFINITY) {
  36. max = 'No';
  37. }
  38. if (min === Number.POSITIVE_INFINITY) {
  39. min = 'No';
  40. }
  41. if (max2 === Number.NEGATIVE_INFINITY) {
  42. max2 = 'No';
  43. }
  44. if (min2 === Number.POSITIVE_INFINITY) {
  45. min2 = 'No';
  46. }
  47.  
  48. console.log(`OddSum=${sum1},
  49. OddMin=${min},
  50. OddMax=${max},
  51. EvenSum=${sum2},
  52. EvenMin=${min2},
  53. EvenMax=${max2}`);
  54.  
  55.  
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement