Skip to content

Commit 7000063

Browse files
committed
ES6 (ex. 6 to 10)
1 parent 3576138 commit 7000063

5 files changed

+76
-6
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
Use the Rest Parameter with Function Parameters:
3+
Modify the function sum using the rest parameter in such a way that the function sum is able to take any number of
4+
arguments and return their sum.
5+
6+
- The result of sum(0,1,2) should be 3
7+
- The result of sum(1,2,3,4) should be 10
8+
- The result of sum(5) should be 5
9+
- The result of sum() should be 0
10+
- sum should be an arrow function which uses the rest parameter syntax (...) on the args parameter.
11+
*/
12+
const sum = (...args) => {
13+
return args.reduce((a, b) => a + b, 0);
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
Use the Spread Operator to Evaluate Arrays In-Place:
3+
Copy all contents of arr1 into another array arr2 using the spread operator.
4+
5+
- arr2 should be correct copy of arr1.
6+
- ... spread operator should be used to duplicate arr1.
7+
- arr2 should remain unchanged when arr1 is changed.
8+
*/
9+
const arr1 = ['JAN', 'FEB', 'MAR', 'APR', 'MAY'];
10+
let arr2;
11+
12+
arr2 = [...arr1]; // Changed this line
13+
14+
console.log(arr2);
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
Use Destructuring Assignment to Extract Values from Objects:
3+
Replace the two assignments with an equivalent destructuring assignment.
4+
It should still assign the variables today and tomorrow the values of today and tomorrow from the HIGH_TEMPERATURES object.
5+
6+
- You should remove the ES5 assignment syntax.
7+
- You should use destructuring to create the today variable.
8+
- You should use destructuring to create the tomorrow variable.
9+
- today should be equal to 77 and tomorrow should be equal to 80.
10+
*/
11+
const HIGH_TEMPERATURES = {
12+
yesterday: 75,
13+
today: 77,
14+
tomorrow: 80
15+
};
16+
17+
// Only change coded below this line
18+
19+
const {today, tomorrow} = HIGH_TEMPERATURES;
20+
21+
// Only change coded above this line
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
Use Destructuring Assignment to Assign Variables from Objects:
3+
Replace the two assignments with an equivalent destructuring assignment.
4+
It should still assign the variables highToday and highTomorrow the values of today and tomorrow from the HIGH_TEMPERATURES object.
5+
6+
- You should remove the ES5 assignment syntax.
7+
- You should use destructuring to create the highToday variable.
8+
- You should use destructuring to create the highTomorrow variable.
9+
- highToday should be equal to 77 and highTomorrow should be equal to 80.
10+
*/
11+
const HIGH_TEMPERATURES = {
12+
yesterday: 75,
13+
today: 77,
14+
tomorrow: 80
15+
};
16+
17+
// Only changed code below this line
18+
19+
const {today: highToday, tomorrow: highTomorrow} = HIGH_TEMPERATURES;
20+
21+
// Only change coded above this line

02-es6/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# ES6
22

3-
My solution proposals for
4-
the [ES6](https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/#es6/) exercises.
3+
My solution proposals for the [ES6](https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/#es6/)
4+
exercises.
55

66
freeCodeCamp module description:
77
> *"ECMAScript, or ES, is a standardized version of JavaScript. Because all major browsers follow this specification, the terms ECMAScript and JavaScript are interchangeable. Most of the JavaScript you've learned up to this point was in ES5 (ECMAScript 5), which was finalized in 2009. While you can still write programs in ES5, JavaScript is constantly evolving, and new features are released every year. ES6, released in 2015, added many powerful new features to the language. In this course, you'll learn these new features, including arrow functions, destructuring, classes, promises, and modules."*
@@ -14,10 +14,10 @@ freeCodeCamp module description:
1414
- [X] [ 04 - Use Arrow Functions to Write Concise Anonymous Functions](04-use-arrow-functions-to-write-concise-anonymous-functions.js)
1515
- [X] [ 05 - Write Arrow Functions with Parameters](05-write-arrow-functions-with-parameters.js)
1616
- [X] [ 06 - Set Default Parameters for Your Functions](06-set-default-parameters-for-your-functions.js)
17-
- [ ] [ 07 - Use the Rest Parameter with Function Parameters]()
18-
- [ ] [ 08 - Use the Spread Operator to Evaluate Arrays In-Place]()
19-
- [ ] [ 09 - Use Destructuring Assignment to Extract Values from Objects]()
20-
- [ ] [ 10 - Use Destructuring Assignment to Assign Variables from Objects]()
17+
- [X] [ 07 - Use the Rest Parameter with Function Parameters](07-use-the-rest-parameter-with-function-parameters.js)
18+
- [X] [ 08 - Use the Spread Operator to Evaluate Arrays In-Place](08-use-the-spread-operator-to-evaluate-arrays-in-place.js)
19+
- [X] [ 09 - Use Destructuring Assignment to Extract Values from Objects](09-use-destructuring-assignment-to-extract-values-from-objects.js)
20+
- [X] [ 10 - Use Destructuring Assignment to Assign Variables from Objects](10-use-destructuring-assignment-to-assign-variables-from-objects.js)
2121
- [ ] [ 11 - Use Destructuring Assignment to Assign Variables from Nested Objects]()
2222
- [ ] [ 12 - Use Destructuring Assignment to Assign Variables from Arrays]()
2323
- [ ] [ 13 - Use Destructuring Assignment with the Rest Parameter to Reassign Array Elements]()

0 commit comments

Comments
 (0)