Skip to content

Commit 1f854b1

Browse files
committedJul 27, 2023
method 2 added
1 parent bebf199 commit 1f854b1

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed
 

‎problem66/problme66.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,16 @@ function calculatePositiveNumbers(arrayOfNumbers){
1919
return total;
2020
};
2121

22-
console.log(calculatePositiveNumbers([2, -5, 10, -3, 7]));
22+
console.log(calculatePositiveNumbers([2, -5, 10, -3, 7]));
23+
24+
/* ------------------------------------------
25+
Solution Two using es6 array method:
26+
------------------------------------------------ */
27+
28+
const totalOfPositiveNumbers = arrayOfNumbers => {
29+
const positiveNumbers = arrayOfNumbers.filter( numbers => numbers > 0);
30+
const total = positiveNumbers.reduce((previous, present) => previous + present , 0);
31+
return total;
32+
}
33+
34+
console.log(totalOfPositiveNumbers([2, -5, 10, -3, 7]));

0 commit comments

Comments
 (0)
Please sign in to comment.