Guest User

Untitled

a guest
Dec 11th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. /**
  2. * @param {number[]} input Массив целых чисел
  3. * @return {number[]}
  4. */
  5. function countPositivesSumNegatives(input) {
  6. if (!Array.isArray(input) || (Array.isArray(input) && input.length === 0)) {
  7. return [];
  8. }
  9.  
  10. let result = [0, 0];
  11. for (let i = 0; i < input.length; i++) {
  12. const item = input[i];
  13.  
  14. if (item > 0) {
  15. result[0] += 1;
  16. } else {
  17. result[1] += item;
  18. }
  19. }
  20. return result;
  21. }
  22.  
  23. countPositivesSumNegatives([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -11, -12, -13, -14, -15]);
  24. countPositivesSumNegatives([0, 2, 3, 0, 5, 6, 7, 8, 9, 10, -11, -12, -13, -14]);
Add Comment
Please, Sign In to add comment