Created
April 30, 2018 22:34
-
-
Save alexko30/705b9f862cf8815262f6e9c89991dfdc to your computer and use it in GitHub Desktop.
sum Of Positive And Negative Elements
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sumOfPositAndNegatElem(arr) { | |
let positiveSum = 0; | |
let negativeSum = 0; | |
for (let i = 0; i < arr.length; i++) { | |
if (arr[i] < 0 || arr[i] == 0) { | |
negativeSum += arr[i]; | |
} else if (arr[i] > 0) { | |
positiveSum += arr[i]; | |
} | |
} | |
console.log(arr); | |
console.log(`Positive sum = ${positiveSum}, and negative sum = ${negativeSum}`); | |
} | |
sumOfPositAndNegatElem([222, -90, 10, -8]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment