Created
December 11, 2018 15:55
-
-
Save denchistyakov/e35e52e6cde6c9cb606f2d37fc2c5267 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** | |
* @param {number[]} input Массив целых чисел | |
* @return {number[]} | |
*/ | |
function countPositivesSumNegatives(input) { | |
if (!Array.isArray(input) || (Array.isArray(input) && input.length === 0)) { | |
return []; | |
} | |
let result = [0, 0]; | |
for (let i = 0; i < input.length; i++) { | |
const item = input[i]; | |
if (item > 0) { | |
result[0] += 1; | |
} else { | |
result[1] += item; | |
} | |
} | |
return result; | |
} | |
countPositivesSumNegatives([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -11, -12, -13, -14, -15]); | |
countPositivesSumNegatives([0, 2, 3, 0, 5, 6, 7, 8, 9, 10, -11, -12, -13, -14]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment