[CHALLENGE] sum positive count negative | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 14

[CHALLENGE] sum positive count negative

Make a function that calculates sum of positive numbers and counts negative numbers. Given array = [1,2,3,4,5,-1,-2,-3,-4,-5] Output: sum of positive numbers = 15 count of negative numbers = 5

16th Feb 2018, 10:01 AM
r8w9
r8w9 - avatar
7 Answers
+ 14
you can now submit challenges in the lesson factory just choose "assignment" and submit your challenge and also var arr = [1,2,3,4,5,-1,-2,-3,-4,-5]; alert(arr.filter(function(v){ return v > 0;}).reduce(function(a, b){return a + b;})); alert(arr.filter(function(v){ return v < 0;}).length);
16th Feb 2018, 10:06 AM
Burey
Burey - avatar
16th Feb 2018, 1:49 PM
LukArToDo
LukArToDo - avatar
+ 9
@Burey I submitted all of my challenges in lesson factory. Btw nice inlines.
16th Feb 2018, 10:10 AM
r8w9
r8w9 - avatar
16th Feb 2018, 1:12 PM
VISHAL SRIVASTAVA
VISHAL SRIVASTAVA - avatar
17th Feb 2018, 11:10 AM
Med Arezki
Med Arezki - avatar
16th Feb 2018, 10:43 AM
Nitzan
Nitzan - avatar
+ 2
The most basic solution in js: https://code.sololearn.com/W8s0WcT036To/#js
16th Feb 2018, 4:03 PM
Pawko
Pawko - avatar