Skip to content

Instantly share code, notes, and snippets.

@denchistyakov
Created December 11, 2018 15:55
Show Gist options
  • Save denchistyakov/e35e52e6cde6c9cb606f2d37fc2c5267 to your computer and use it in GitHub Desktop.
Save denchistyakov/e35e52e6cde6c9cb606f2d37fc2c5267 to your computer and use it in GitHub Desktop.
/**
* @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