Skip to content

Commit 3773eb1

Browse files
author
JorvanW
committed
Updated code of sum.js to return null if there are only non-numeric inputs only.
1 parent 11f5bfe commit 3773eb1

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

‎Sprint-1/implement/sum.js‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
function sum(elements) {
22
elements = elements.filter(element => typeof element === 'number');
3-
let total = 0;
4-
5-
for (let element of elements) {
3+
if (elements.length === 0) {
4+
return null;}
5+
6+
let total = 0;
7+
8+
for (let element of elements) {
69
total += element;
710
// += means to add to the current value and assign as result
811
// elements are individual items inside a collection (not just string)

0 commit comments

Comments
 (0)