Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @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]);
Add Comment
Please, Sign In to add comment