Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1f854b1

Browse files
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‎

Lines changed: 13 additions & 1 deletion
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)

AltStyle によって変換されたページ (->オリジナル) /