Skip to content
This repository was archived by the owner on Mar 20, 2023. It is now read-only.

Commit 619ef9a

Browse files
committed
refactor add2
1 parent 8dbda53 commit 619ef9a

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

add/add.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ function add(param1: number, param2: number): number {
22
return param1 + param2;
33
}
44

5-
function add2(param1: number[]): number {
6-
let sum = 0;
7-
for (let i = 0; i < arguments.length; i++){
8-
sum += arguments[i];
9-
}
10-
return sum;
5+
function add2(...param1: number[]): number {
6+
let total = 0;
7+
param1.forEach(function(el){
8+
total += el;
9+
});
10+
return total;
1111
}
1212
console.log(add(1, 2));
1313
console.log(add(3, 2));

0 commit comments

Comments
 (0)