Skip to content

Commit 6ebe5b5

Browse files
Activity 3 completed for Day-8
Co-authored-by: Senior Dev'Codes
1 parent 2390088 commit 6ebe5b5

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

Day8/index.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,24 @@ console.log(`Title: ${title}, Author: ${author}`);
3636

3737

3838
console.log("-------------------------------------------------");
39-
console.log("Activity 3: ");
39+
console.log("Activity 3: ");
40+
41+
// Task 5: Use the spread operator to create a new array that includes all elements of an existing array plus additional elements, and log the new array to the console.
42+
43+
arr1 = [1, 2, 3];
44+
arr2 = [4, 5, 6];
45+
46+
newarr = [...arr1, ...arr2];
47+
console.log(`New Array: ${newarr}`);
48+
49+
// Use the rest operator in a function to accept an arbitrary number of arguments, sum them, and return the result.
50+
51+
function sum(...theArgs) {
52+
let total = 0;
53+
for (const arg of theArgs) {
54+
total += arg;
55+
}
56+
return total;
57+
}
58+
59+
console.log(`Sum of 1, 2, 3, 4, 5: ${sum(1, 2, 3, 4, 5)}`);

0 commit comments

Comments
 (0)