Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function OddEvenPosition(inputParameters) {
- oddSum = 0
- evenSum = 0
- oddMin = Number.NEGATIVE_INFINITY
- oddMax = Number.POSITIVE_INFINITY
- evenMin = Number.NEGATIVE_INFINITY
- evenMax = Number.POSITIVE_INFINITY
- for (var i = 1; i < inputParameters.length; i++) {
- if (i % 2 == 0) {
- evenSum += Number(inputParameters[i])
- let currentNumber = Number(inputParameters[i])
- if (currentNumber > evenMin) {
- evenMin = currentNumber
- } else if (currentNumber < evenMax) {
- evenMax = currentNumber
- }
- } else {
- oddSum += Number(inputParameters[i])
- let currentNumber = Number(inputParameters[i])
- if (currentNumber > oddMin) {
- oddMin = currentNumber
- } else if (currentNumber < oddMax) {
- oddMax = currentNumber
- }
- }
- }
- console.log('oddsum '+oddSum)
- if (oddSum == 0) {
- console.log("oddmin No")
- console.log("oddmax No")
- } else {
- if (oddMin == oddSum) {
- console.log('oddmin '+oddMin)
- } else {
- console.log('oddmin '+oddMax)
- }
- console.log('oddmax '+oddMin)
- }
- console.log('evensum '+evenSum)
- if (evenSum == 0) {
- console.log('evenmin No')
- console.log('evenmax No')
- } else {
- if (evenMin == evenSum) {
- console.log('evenmin '+evenMin)
- } else {
- console.log('evenmin '+evenMax)
- }
- console.log('evenmax '+evenMin)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement