Skip to content

Commit 51f5114

Browse files
committed
Use pop instead of shift
1 parent 8049c08 commit 51f5114

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

Solutions/3-while.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
const sum = (...args) => {
44
let value = 0;
55
while (args.length > 0) {
6-
value += args.shift();
6+
value += args.pop();
77
}
88
return value;
99
};

Solutions/4-do-while.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const sum = (...args) => {
44
if (args.length === 0) return 0;
55
let value = 0;
66
do {
7-
value += args.shift();
7+
value += args.pop();
88
} while (args.length > 0);
99
return value;
1010
};

0 commit comments

Comments
 (0)