Advertisement
Guest User

11. Odd / Even Position JavaScript

a guest
Jun 24th, 2017
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. function OddEvenPosition(inputParameters) {
  2. oddSum = 0
  3. evenSum = 0
  4. oddMin = Number.NEGATIVE_INFINITY
  5. oddMax = Number.POSITIVE_INFINITY
  6. evenMin = Number.NEGATIVE_INFINITY
  7. evenMax = Number.POSITIVE_INFINITY
  8. for (var i = 1; i < inputParameters.length; i++) {
  9. if (i % 2 == 0) {
  10. evenSum += Number(inputParameters[i])
  11.  
  12. let currentNumber = Number(inputParameters[i])
  13.  
  14. if (currentNumber > evenMin) {
  15. evenMin = currentNumber
  16.  
  17.  
  18. } else if (currentNumber < evenMax) {
  19. evenMax = currentNumber
  20.  
  21. }
  22. } else {
  23. oddSum += Number(inputParameters[i])
  24.  
  25. let currentNumber = Number(inputParameters[i])
  26. if (currentNumber > oddMin) {
  27. oddMin = currentNumber
  28. } else if (currentNumber < oddMax) {
  29. oddMax = currentNumber
  30. }
  31. }
  32.  
  33.  
  34.  
  35. }
  36.  
  37.  
  38.  
  39. console.log('oddsum '+oddSum)
  40. if (oddSum == 0) {
  41. console.log("oddmin No")
  42. console.log("oddmax No")
  43. } else {
  44. if (oddMin == oddSum) {
  45. console.log('oddmin '+oddMin)
  46. } else {
  47. console.log('oddmin '+oddMax)
  48. }
  49. console.log('oddmax '+oddMin)
  50. }
  51.  
  52. console.log('evensum '+evenSum)
  53. if (evenSum == 0) {
  54. console.log('evenmin No')
  55. console.log('evenmax No')
  56. } else {
  57. if (evenMin == evenSum) {
  58. console.log('evenmin '+evenMin)
  59. } else {
  60. console.log('evenmin '+evenMax)
  61. }
  62.  
  63. console.log('evenmax '+evenMin)
  64. }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement