-
@@ -28,7 +25,10 @@
- [for of loop](#for-of-loop)
- [break](#break)
- [continue](#continue)
- - [π» Exercises:Day 6](#-exercisesday-6)
+ - [π» Exercises:Day 6](#%f0%9f%92%bb-exercisesday-6)
+ - [Exercises: Level 1](#exercises-level-1)
+ - [Exercises: Level 2](#exercises-level-2)
+ - [Exercises: Level 3](#exercises-level-3)
# π Day 6
@@ -217,6 +217,8 @@ content will added soon
## π» Exercises:Day 6
+### Exercises: Level 1
+
```js
const countries = [
'Albania',
@@ -322,7 +324,9 @@ content will added soon
5j2khz
```
-16. Develop a small script which generate any number of characters random id:
+### Exercises: Level 2
+
+1. Develop a small script which generate any number of characters random id:
```sh
fe3jo1gl124g
@@ -332,31 +336,31 @@ content will added soon
xkqci4utda1lmbelpkm03rba
```
-17. Write a script which generates a random hexadecimal number.
+1. Write a script which generates a random hexadecimal number.
```sh
'#ee33df'
```
-18. Write a script which generates a random rgb color number.
+1. Write a script which generates a random rgb color number.
```sh
rgb(240,180,80)
```
-19. Using the above countries array, create the following new array.
+1. Using the above countries array, create the following new array.
```sh
["ALBANIA", "BOLIVIA", "CANADA", "DENMARK", "ETHIOPIA", "FINLAND", "GERMANY", "HUNGARY", "IRELAND", "JAPAN", "KENYA"]
```
-20. Using the above countries array, create an array for countries length'.
+1. Using the above countries array, create an array for countries length'.
```sh
[7, 7, 6, 7, 8, 7, 7, 7, 7, 5, 5]
```
-21. Use the countries array to create the following array of arrays:
+1. Use the countries array to create the following array of arrays:
```sh
[
@@ -374,42 +378,41 @@ content will added soon
]
```
-22. In above countries array, check if there is a country or countries containing the word 'land'. If there are countries containing 'land', print it as array. If there is no country containing the word 'land', print 'These are countries without land'.
+1. In above countries array, check if there is a country or countries containing the word 'land'. If there are countries containing 'land', print it as array. If there is no country containing the word 'land', print 'All these are countries without land'.
```sh
['Finland', 'Iceland']
```
-23. In above countries array, check if there a country or countries end with a substring 'ia'. If there are countries end with, print it as array. If there is no country containing the word 'land', print 'These are countries ends without ia'.
+1. In above countries array, check if there is a country or countries end with a substring 'ia'. If there are countries end with, print it as array. If there is no country containing the word 'ai', print 'These are countries ends without ia'.
```sh
['Albania', 'Bolivia','Ethiopia']
```
-24. Using the above countries array, find the country containing the biggest number of characters.
+1. Using the above countries array, find the country containing the biggest number of characters.
```sh
Ethiopia
```
-25. Using the above countries array, find the country containing only 5 characters.
+1. Using the above countries array, find the country containing only 5 characters.
```sh
['Japan', 'Kenya']
```
-26. Find the longest word in the webTechs array
-27. Use the webTechs are to create the following array of arrays:
+1. Find the longest word in the webTechs array
+1. Use the webTechs are to create the following array of arrays:
```sh
[["HTML", 4], ["CSS", 3],["JavaScript", 10],["React", 5],["Redux", 5],["Node", 4],["MongoDB", 7]]
```
-28. An application created using MongoDB, Express, React and Node is called a MERN stack. Create the acronym MERN by using the array mernStack
-
-29. Iterate through the array, ["HTML", "CSS", "JS", "React", "Redux", "Node", "Express", "MongoDB"] using a for loop or for of loop and print out the items.
-30. This is a fruit array , ['banana', 'orange', 'mango', 'lemon'] reverse the order using loop without using a reverse method.
-31. Print all the elements of array as shown below.
+1. An application created using MongoDB, Express, React and Node is called a MERN stack. Create the acronym MERN by using the array mernStack
+1. Iterate through the array, ["HTML", "CSS", "JS", "React", "Redux", "Node", "Express", "MongoDB"] using a for loop or for of loop and print out the items.
+1. This is a fruit array , ['banana', 'orange', 'mango', 'lemon'] reverse the order using loop without using a reverse method.
+1. Print all the elements of array as shown below.
```js
const fullStack = [
@@ -427,15 +430,18 @@ content will added soon
EXPRESS
MONGODB
```
-32. Copy countries array(Avoid mutation)
-33. Arrays are mutable. Create a copy of array which does not modify the original. Sort the copied array and store in a variable sortedCountries
-34. Sort the webTechs array and mernStack array
-35. Extract all the countries contain the word 'land' from the [countries array](https://github.com/Asabeneh/30DaysOfJavaScript/tree/master/data/countries.js) and print it as array
-36. Find the country containing the hightest number of characters in the [countries array](https://github.com/Asabeneh/30DaysOfJavaScript/tree/master/data/countries.js)
-37. Extract all the countries contain the word 'land' from the [countries array](https://github.com/Asabeneh/30DaysOfJavaScript/tree/master/data/countries.js) and print it as array
-38. Extract all the countries containing only four characters from the [countries array](https://github.com/Asabeneh/30DaysOfJavaScript/tree/master/data/countries.js) and print it as array
-39. Extract all the countries containing two or more words from the [countries array](https://github.com/Asabeneh/30DaysOfJavaScript/tree/master/data/countries.js) and print it as array
-40. Reverse the [countries array](https://github.com/Asabeneh/30DaysOfJavaScript/tree/master/data/countries.js) and capitalize each country and stored it as an array
+
+### Exercises: Level 3
+
+1. Copy countries array(Avoid mutation)
+1. Arrays are mutable. Create a copy of array which does not modify the original. Sort the copied array and store in a variable sortedCountries
+1. Sort the webTechs array and mernStack array
+1. Extract all the countries contain the word 'land' from the [countries array](https://github.com/Asabeneh/30DaysOfJavaScript/tree/master/data/countries.js) and print it as array
+1. Find the country containing the hightest number of characters in the [countries array](https://github.com/Asabeneh/30DaysOfJavaScript/tree/master/data/countries.js)
+1. Extract all the countries contain the word 'land' from the [countries array](https://github.com/Asabeneh/30DaysOfJavaScript/tree/master/data/countries.js) and print it as array
+1. Extract all the countries containing only four characters from the [countries array](https://github.com/Asabeneh/30DaysOfJavaScript/tree/master/data/countries.js) and print it as array
+1. Extract all the countries containing two or more words from the [countries array](https://github.com/Asabeneh/30DaysOfJavaScript/tree/master/data/countries.js) and print it as array
+1. Reverse the [countries array](https://github.com/Asabeneh/30DaysOfJavaScript/tree/master/data/countries.js) and capitalize each country and stored it as an array
π CONGRATULATIONS ! π
diff --git a/07_Day/07_day_functions.md b/07_Day/07_day_functions.md
index 1bf1e1c..db435b0 100644
--- a/07_Day/07_day_functions.md
+++ b/07_Day/07_day_functions.md
@@ -1,8 +1,5 @@
30 Days Of JavaScript
-
@@ -37,7 +34,10 @@
- [Arrow Function](#arrow-function)
- [Function with default parameters](#function-with-default-parameters)
- [Function declaration versus Arrow function](#function-declaration-versus-arrow-function)
- - [π» Exercises](#-exercises)
+ - [π» Exercises](#%f0%9f%92%bb-exercises)
+ - [Exercises: Level 1](#exercises-level-1)
+ - [Exercises: Level 2](#exercises-level-2)
+ - [Exercises: Level 3](#exercises-level-3)
# π Day 7
@@ -507,6 +507,8 @@ console.log('Weight of an object in Newton: ', weightOfObject(100, 1.62)) // gra
## π» Exercises
+### Exercises: Level 1
+
1. Declare a function _fullName_ and it print out your full name.
2. Declare a function _fullName_ and now it takes firstName, lastName as a parameter and it returns your full - name.
3. Declare a function _addNumbers_ and it takes two two parameters and it returns sum.
@@ -536,9 +538,11 @@ console.log('Weight of an object in Newton: ', weightOfObject(100, 1.62)) // gra
console.log(findMax(0, -10, -2))
0
```
+
+### Exercises: Level 2
-16. Linear equation is calculated as follows: _ax + by + c = 0_. Write a function which calculates value of a linear equation, _solveLinEquation_.
-17. Quadratic equation is calculated as follows: _ax2 + bx + c = 0_. Write a function which calculates value or values of a quadratic equation, _solveQuadEquation_.
+1. Linear equation is calculated as follows: _ax + by + c = 0_. Write a function which calculates value of a linear equation, _solveLinEquation_.
+1. Quadratic equation is calculated as follows: _ax2 + bx + c = 0_. Write a function which calculates value or values of a quadratic equation, _solveQuadEquation_.
```js
console.log(solveQuadratic()) // {0}
@@ -549,22 +553,22 @@ console.log('Weight of an object in Newton: ', weightOfObject(100, 1.62)) // gra
console.log(solveQuadratic(1, -1, 0)) //{1, 0}
```
-18. Declare a function name _printArray_. It takes array as a parameter and it prints out each value of the array.
-19. 11. Write a function name _showDateTime_ which shows time in this format: 08/01/2020 04:08 using the Date object.
+1. Declare a function name _printArray_. It takes array as a parameter and it prints out each value of the array.
+1. Write a function name _showDateTime_ which shows time in this format: 08/01/2020 04:08 using the Date object.
```sh
showDateTime()
08/01/2020 04:08
```
-20. Declare a function name _swapValues_. This function swaps value of x to y.
+1. Declare a function name _swapValues_. This function swaps value of x to y.
```js
swapValues(3, 4) // x => 4, y=>3
swapValues(4, 5) // x = 5, y = 4
```
-21. Declare a function name _reverseArray_. It takes array as a parameter and it returns the reverse of the array (don't use method).
+1. Declare a function name _reverseArray_. It takes array as a parameter and it returns the reverse of the array (don't use method).
```js
console.log(reverseArray([1, 2, 3, 4, 5]))
@@ -573,13 +577,13 @@ console.log('Weight of an object in Newton: ', weightOfObject(100, 1.62)) // gra
//['C', 'B', 'A']
```
-22. Declare a function name _capitalizeArray_. It takes array as a parameter and it returns the - capitalizedarray.
-23. Declare a function name _addItem_. It takes an item parameter and it returns an array after adding the item
-24. Declare a function name _removeItem_. It takes an index parameter and it returns an array after removing an item
-25. Declare a function name _sumOfNumbers_. It takes a number parameter and it adds all the numbers in that range.
-26. Declare a function name _sumOfOdds_. It takes a number parameter and it adds all the odd numbers in that - range.
-27. Declare a function name _sumOfEven_. It takes a number parameter and it adds all the even numbers in that - range.
-28. Declare a function name evensAndOdds . It takes a positive integer as parameter and it counts number of evens and odds in the number.
+1. Declare a function name _capitalizeArray_. It takes array as a parameter and it returns the - capitalizedarray.
+1. Declare a function name _addItem_. It takes an item parameter and it returns an array after adding the item
+1. Declare a function name _removeItem_. It takes an index parameter and it returns an array after removing an item
+1. Declare a function name _sumOfNumbers_. It takes a number parameter and it adds all the numbers in that range.
+1. Declare a function name _sumOfOdds_. It takes a number parameter and it adds all the odd numbers in that - range.
+1. Declare a function name _sumOfEven_. It takes a number parameter and it adds all the even numbers in that - range.
+1. Declare a function name evensAndOdds . It takes a positive integer as parameter and it counts number of evens and odds in the number.
```sh
evensAndOdds(100);
@@ -587,30 +591,32 @@ console.log('Weight of an object in Newton: ', weightOfObject(100, 1.62)) // gra
The number of evens are 51.
```
-29. Write a function which takes any number of arguments and return the sum of the arguments
+1. Write a function which takes any number of arguments and return the sum of the arguments
```js
sum(1, 2, 3) // -> 6
sum(1, 2, 3, 4) // -> 10
```
-30. Writ a function which generates a _randomUserIp_.
-31. Write a function which generates a _randomMacAddress_
-32. Declare a function name _randomHexaNumberGenerator_. When this function is called it generates a random hexadecimal number. The function return the hexadecimal number.
+1. Writ a function which generates a _randomUserIp_.
+1. Write a function which generates a _randomMacAddress_
+1. Declare a function name _randomHexaNumberGenerator_. When this function is called it generates a random hexadecimal number. The function return the hexadecimal number.
```sh
console.log(randomHexaNumberGenerator());
'#ee33df'
```
-33. Declare a function name _userIdGenerator_. When this function is called it generates seven character id. The function return the id.
+1. Declare a function name _userIdGenerator_. When this function is called it generates seven character id. The function return the id.
```sh
console.log(userIdGenerator());
41XTDbE
```
-34. Modify question number n . Declare a function name _userIdGeneratedByUser_. It doesnβt take any parameter but it takes two inputs using prompt(). One of the input is the number of characters and the second input is the number of ids which are supposed to be generated.
+### Exercises: Level 3
+
+1. Modify question number n . Declare a function name _userIdGeneratedByUser_. It doesnβt take any parameter but it takes two inputs using prompt(). One of the input is the number of characters and the second input is the number of ids which are supposed to be generated.
```sh
userIdGeneratedByUser()
@@ -629,18 +635,18 @@ console.log('Weight of an object in Newton: ', weightOfObject(100, 1.62)) // gra
'
```
-35. Write a function name _rgbColorGenerator_ and it generates rgb colors.
+1. Write a function name _rgbColorGenerator_ and it generates rgb colors.
```sh
rgbColorGenerator()
rgb(125,244,255)
```
-36. Write a function **_arrayOfHexaColors_** which return any number of hexadecimal colors in an array.
-37. Write a function **_arrayOfRgbColors_** which return any number of RGB colors in an array.
-38. Write a function **_convertHexaToRgb_** which converts hexa color to rgb and it returns an rgb color.
-39. Write a function **_convertRgbToHexa_** which converts rgb to hexa color and it returns an hexa color.
-40. Write a function **_generateColors_** which can generate any number of hexa or rgb colors.
+1. Write a function **_arrayOfHexaColors_** which return any number of hexadecimal colors in an array.
+1. Write a function **_arrayOfRgbColors_** which return any number of RGB colors in an array.
+1. Write a function **_convertHexaToRgb_** which converts hexa color to rgb and it returns an rgb color.
+1. Write a function **_convertRgbToHexa_** which converts rgb to hexa color and it returns an hexa color.
+1. Write a function **_generateColors_** which can generate any number of hexa or rgb colors.
```js
console.log(generateColors('hexa', 3)) // ['#a3e12f', '#03ed55', '#eb3d2b']
@@ -649,34 +655,50 @@ console.log('Weight of an object in Newton: ', weightOfObject(100, 1.62)) // gra
console.log(generateColors('rgb', 1)) // 'rgb(33,79, 176)'
```
-41. Call your function _shuffleArray_, it takes an array as a parameter and it returns a shuffled array
-42. Call your function _factorial_, it takes a whole number as a parameter and it return a factorial of the number
-43. Call your function _isEmpty_, it takes a parameter and it checks if it is empty or not
-44. Call your function _sum_, it takes any number of arguments and it returns the sum.
-45. Write a function called _sumOfArrayItems_, it takes an array parameter and return the sum of all the items. Check if all the array items are number types. If not give return reasonable feedback.
-46. Write a function called _average_, it takes an array parameter and returns the average of the items. Check if all the array items are number types. If not give return reasonable feedback.
-47. Write a function called _modifyArray_ takes array as parameter and modifies the fifth item of the array and return the array. If the array length is less than five it return 'item not found'.
+1. Call your function _shuffleArray_, it takes an array as a parameter and it returns a shuffled array
+1. Call your function _factorial_, it takes a whole number as a parameter and it return a factorial of the number
+1. Call your function _isEmpty_, it takes a parameter and it checks if it is empty or not
+1. Call your function _sum_, it takes any number of arguments and it returns the sum.
+1. Write a function called _sumOfArrayItems_, it takes an array parameter and return the sum of all the items. Check if all the array items are number types. If not give return reasonable feedback.
+1. Write a function called _average_, it takes an array parameter and returns the average of the items. Check if all the array items are number types. If not give return reasonable feedback.
+1. Write a function called _modifyArray_ takes array as parameter and modifies the fifth item of the array and return the array. If the array length is less than five it return 'item not found'.
```js
console.log(modifyArray(['Avocado', 'Tomato', 'Potato','Mango', 'Lemon','Carrot']);
- // β['Avocado', 'Tomato', 'Potato','Mango', 'LEMON', 'Carrot']
+ ```
+
+ ```sh
+ ['Avocado', 'Tomato', 'Potato','Mango', 'LEMON', 'Carrot']
+ ```
+
+ ```js
console.log(modifyArray(['Google', 'Facebook','Apple', 'Amazon','Microsoft', 'IBM']);
- // β['Google', 'Facebook','Apple', 'Amazon','MICROSOFT', 'IBM']
+ ```
+
+ ```sh
+ ['Google', 'Facebook','Apple', 'Amazon','MICROSOFT', 'IBM']
+ ```
+
+ ```js
console.log(modifyArray(['Google', 'Facebook','Apple', 'Amazon']);
- // β'Not Found'
```
-48. Write a function called _isPrime_, which checks if a number is prime number.
-49. Write a functions which checks if all items are unique in the array.
-50. Write a function which checks if all the items of the array are the same data type.
-51. JavaScript variable name does not support special characters or symbols except \$ or \_. Write a function **\*isValidVariable** which check if a variable is valid or invalid variable.
-52. Write a function which returns array of seven random numbers in a range of 0-9. All the numbers must be unique.
+ ```sh
+ 'Not Found'
+ ```
+
+1. Write a function called _isPrime_, which checks if a number is prime number.
+1. Write a functions which checks if all items are unique in the array.
+1. Write a function which checks if all the items of the array are the same data type.
+1. JavaScript variable name does not support special characters or symbols except \$ or \_. Write a function **isValidVariable** which check if a variable is valid or invalid variable.
+1. Write a function which returns array of seven random numbers in a range of 0-9. All the numbers must be unique.
```js
- sevenRandomNumbers()[(1, 4, 5, 7, 9, 8, 0)]
+ sevenRandomNumbers()
+ [(1, 4, 5, 7, 9, 8, 0)]
```
-53. Write a function called reverseCountries, it takes countries array and first it copy the array and returns the reverse of the original array
+1. Write a function called reverseCountries, it takes countries array and first it copy the array and returns the reverse of the original array
π CONGRATULATIONS ! π
diff --git a/08_Day/08_day_objects.md b/08_Day/08_day_objects.md
index 8995dec..c8a6ec5 100644
--- a/08_Day/08_day_objects.md
+++ b/08_Day/08_day_objects.md
@@ -1,8 +1,5 @@
[<< Day 7](https://github.com/Asabeneh/30DaysOfJavaScript/blob/master/07_Day/07_day_functions.md) | [Day 9 >>](https://github.com/Asabeneh/30DaysOfJavaScript/blob/master/09_Day/09_day_higher_order_functions.md)
@@ -38,6 +34,8 @@
- [Getting object keys and values using Object.entries()](#getting-object-keys-and-values-using-objectentries)
- [Checking properties using hasOwnProperty()](#checking-properties-using-hasownproperty)
- [π» Exercises](#%f0%9f%92%bb-exercises)
+ - [Exercises: Level 1](#exercises-level-1)
+ - [Exercises: Level 2](#exercises-level-2)
# π Day 8
@@ -422,12 +420,17 @@ console.log(copyPerson.hasOwnProperty('score'))
## π» Exercises
+### Exercises: Level 1
+
1. Create an empty object called dog
1. Print the the dog object on the console
1. Add name, legs, color, age and bark properties for the dog object. The bark property is a method which return _woof woof_
1. Get name, legs, color, age and bark value from the dog object
1. Set new properties the dog object: breed, getDogInfo
-1. Create an object literal called _personAccount_. It has _firstName, lastName, incomes, expenses_ properties and it has _totalIncome, totalExpense, accountInfo,addIncome, addExpense_ and _accountBalance_ methods. Incomes is a set of incomes and its description and expenses is a set of incomes and its description.
+
+### Exercises: Level 2
+
+1. Find the person who has many skills in the users object.
1. Count logged in users,count users having greater than equal to 50 points from the following object.
````js
@@ -483,14 +486,101 @@ console.log(copyPerson.hasOwnProperty('score'))
}
}```
- ````
-
1. Find people who are MERN stack developer from the users object
1. Set your name in the users object without modifying the original users object
1. Get all keys or properties of users object
1. Get all the values of users object
1. Use the countries object to print a country name, capital, populations and languages.
+### Exercises: Level 3
+
+1. Create an object literal called _personAccount_. It has _firstName, lastName, incomes, expenses_ properties and it has _totalIncome, totalExpense, accountInfo,addIncome, addExpense_ and _accountBalance_ methods. Incomes is a set of incomes and its description and expenses is a set of incomes and its description.
+2. **** Questions:2, 3 and 4 are based on the following two arrays:users and products ()
+
+ ```js
+ const users = [
+ {
+ _id: 'ab12ex',
+ username: 'Alex',
+ email: 'alex@alex.com',
+ password: '123123',
+ createdAt:'08/01/2020 9:00 AM',
+ isLoggedIn: false
+ },
+ {
+ _id: 'fg12cy',
+ username: 'Asab',
+ email: 'asab@asab.com',
+ password: '123456',
+ createdAt:'08/01/2020 9:30 AM',
+ isLoggedIn: true
+ },
+ {
+ _id: 'zwf8md',
+ username: 'Brook',
+ email: 'brook@brook.com',
+ password: '123111',
+ createdAt:'08/01/2020 9:45 AM',
+ isLoggedIn: true
+ },
+ {
+ _id: 'eefamr',
+ username: 'Martha',
+ email: 'martha@martha.com',
+ password: '123222',
+ createdAt:'08/01/2020 9:50 AM',
+ isLoggedIn: false
+ },
+ {
+ _id: 'ghderc',
+ username: 'Thomas',
+ email: 'thomas@thomas.com',
+ password: '123333',
+ createdAt:'08/01/2020 10:00 AM',
+ isLoggedIn: false
+ }
+ ];
+
+ const products = [
+ {
+ _id: 'eedfcf',
+ name: 'mobile phone',
+ description: 'Huawei Honor',
+ price: 200,
+ ratings: [
+ { userId: 'fg12cy', rate: 5 },
+ { userId: 'zwf8md', rate: 4.5 }
+ ],
+ likes: []
+ },
+ {
+ _id: 'aegfal',
+ name: 'Laptop',
+ description: 'MacPro: System Darwin',
+ price: 2500,
+ ratings: [],
+ likes: ['fg12cy']
+ },
+ {
+ _id: 'hedfcg',
+ name: 'TV',
+ description: 'Smart TV:Procaster',
+ price: 400,
+ ratings: [{ userId: 'fg12cy', rate: 5 }],
+ likes: ['fg12cy']
+ }
+ ]
+ ```
+
+ Imagine you are getting the above users collection from a MongoDB database.
+ a. Create a function called signUp which allows user to add to the collection. If user exists, inform the user that he has already an account.
+ b. Create a function called signIn which allows user to sign in to the application
+3. The products array has three elements and each of them has six properties.
+ a. Create a function called rateProduct which rates the product
+ b. Create a function called averageRating which calculate the average rating of a product
+
+4. Create a function called likeProduct. This function will helps to like to the product if it is not liked and remove like if it was liked.
+
π CONGRATULATIONS ! π
diff --git a/09_Day/09_day_higher_order_functions.md b/09_Day/09_day_higher_order_functions.md
index 58af802..8999fa7 100644
--- a/09_Day/09_day_higher_order_functions.md
+++ b/09_Day/09_day_higher_order_functions.md
@@ -1,8 +1,5 @@
-[<< Day 8](https://github.com/Asabeneh/30DaysOfJavaScript/blob/master/08_Day/08_day_objects.md) | [Day 10 >>](#)
+[<< Day 8](https://github.com/Asabeneh/30DaysOfJavaScript/blob/master/08_Day/08_day_objects.md) | [Day 10 >>](https://github.com/Asabeneh/30DaysOfJavaScript/blob/master/10_Day/10_day_Set_and_Map.md)

@@ -25,7 +21,7 @@
- [Higher Order Function](#higher-order-function)
- [Callback](#callback)
- [Returning function](#returning-function)
- - [setTime](#settime)
+ - [setting time](#setting-time)
- [setInterval](#setinterval)
- [setTimeout](#settimeout)
- [Functional Programming](#functional-programming)
@@ -35,13 +31,17 @@
- [reduce](#reduce)
- [every](#every)
- [find](#find)
- - [some](#some)
- [findIndex](#findindex)
+ - [some](#some)
- [sort](#sort)
- [Sorting string values](#sorting-string-values)
- [Sorting Numeric values](#sorting-numeric-values)
- [Sorting Object Arrays](#sorting-object-arrays)
- [π» Exercises](#%f0%9f%92%bb-exercises)
+ - [Exercises: Level 1](#exercises-level-1)
+ - [Exercises: Level 2](#exercises-level-2)
+ - [Exercises: Level 3](#exercises-level-3)
+
# Day 9
## Higher Order Function
@@ -54,7 +54,7 @@ A callback is a function which can be passed as parameter to other function. See
```js
// a callback function, the function could be any name
-const callBack = (n) => {
+const callback = (n) => {
return n ** 2
}
β
@@ -63,13 +63,14 @@ function cube(callback, n) {
return callback(n) * n
}
β
-console.log(cube(square, 3))
+console.log(cube(callback, 3))
```
### Returning function
Higher order functions return function as a value
β
+
```js
// Higher order function returning an other function
const higherOrder = n => {
@@ -85,7 +86,7 @@ const higherOrder = n => {
console.log(higherOrder(2)(3)(10))
```
-Let us see were we use call back functions.For instance the *forEach* method uses call back.
+Let us see were we use call back functions.For instance the _forEach_ method uses call back.
```js
const numbers = [1, 2, 3, 4]
@@ -97,11 +98,15 @@ const sumArray = arr => {
}
numbers.forEach(callback)
return sum
-
+
}
console.log(sumArray(numbers))
```
+```sh
+15
+```
+
The above example can be simplified as follows:
```js
@@ -113,12 +118,21 @@ const sumArray = arr => {
sum += element
})
return sum
-
+
}
console.log(sumArray(numbers))
```
-### setTime
+```sh
+15
+```
+
+### setting time
+
+In JavaScript we can execute some activity on certain interval of time or we can schedule(wait) for sometime to execute some activities.
+
+- setInterval
+- setTimeout
#### setInterval
@@ -126,15 +140,14 @@ In JavaScript, we use setInterval higher order function to do some activity cont
```js
// syntax
-function callBack () {
+function callBack() {
// code goes here
}
setInterval(callback, duration)
```
```js
-
-function sayHello () {
+function sayHello() {
console.log('Hello')
}
setInterval(sayHello, 2000) // it prints hello in every 2 seconds
@@ -146,15 +159,14 @@ In JavaScript, we use setTimeout higher order function to execute some action at
```js
// syntax
-function callBack () {
+function callback() {
// code goes here
}
setTimeout(callback, duration) // duration in milliseconds
```
```js
-
-function sayHello () {
+function sayHello() {
console.log('Hello')
}
setTimeout(sayHello, 2000) // it prints hello after it waits for 2 seconds.
@@ -162,14 +174,14 @@ setTimeout(sayHello, 2000) // it prints hello after it waits for 2 seconds.
## Functional Programming
-Instead of writing regular loop, latest version of JavaScript introduced lots of built in methods which can help us to solve complicated problems. All builtin methods take callback function. In this section, we will see *forEach*, *map*, *filter*, *reduce*, *find*, *every*, *some*, and *sort*.
+Instead of writing regular loop, latest version of JavaScript introduced lots of built in methods which can help us to solve complicated problems. All builtin methods take callback function. In this section, we will see _forEach_, _map_, _filter_, _reduce_, _find_, _every_, _some_, and _sort_.
### forEach
-*forEach*: Iterate an array elements. We use *forEach* only with arrays. It takes a callback function with elements, index parameter and array itself. The index and the array optional.
+_forEach_: Iterate an array elements. We use _forEach_ only with arrays. It takes a callback function with elements, index parameter and array itself. The index and the array optional.
```js
-arr.forEach(function(element, index, arr){
+arr.forEach(function(element, index, arr) {
console.log(index, element, arr)
})
// The above code can be written using arrow function
@@ -180,11 +192,32 @@ arr.forEach((element, index, arr) => {
arr.forEach((element, index, arr) => console.log(index, element, arr))
```
+```js
+let sum = 0;
+const numbers = [1,2,3,4,5];
+numbers.forEach(num => console.log(num)))
+
+console.log(sum)
+```
+
+```sh
+1
+2
+3
+4
+5
+```
+
```js
let sum = 0;
const numbers = [1,2,3,4,5];
numbers.forEach(num => sum += num))
-// 15
+
+console.log(sum)
+```
+
+```sh
+15
```
```js
@@ -202,10 +235,10 @@ ICELAND
### map
-*map*: Iterate an array elements and modify the array elements. It takes a callback function with elements and index parameter and return the modified array.
+_map_: Iterate an array elements and modify the array elements. It takes a callback function with elements and index parameter and return a new array.
```js
-const modifiedArray = arr.map(function(element, index){
+const modifiedArray = arr.map(function(element, index) {
return element
})
```
@@ -215,15 +248,24 @@ const modifiedArray = arr.map(function(element, index){
const modifiedArray = arr.map((element,index) => element);
*/
//Example
-const numbers = [1,2,3,4,5]
-const numbersSquare = numbers.map((num) => num * num)
-console.log(numbersSquare) // [1,4,9,16,25]
+const numbers = [1, 2, 3, 4, 5]
+const numbersSquare = numbers.map(num => num * num)
+
+console.log(numbersSquare)
+```
+
+```sh
+[1, 4, 9, 16, 25]
```
```js
const names = ['Asabeneh', 'Mathias', 'Elias', 'Brook']
-const namesToUpperCase = names.map((name) => name.toUpperCase())
-console.log(namesToUpperCase) //['ASABENEH', 'MATHIAS', 'ELIAS', 'BROOK']
+const namesToUpperCase = names.map(name => name.toUpperCase())
+console.log(namesToUpperCase)
+```
+
+```sh
+['ASABENEH', 'MATHIAS', 'ELIAS', 'BROOK']
```
```js
@@ -240,13 +282,9 @@ const countries = [
'Japan',
'Kenya'
]
-const countriesToUpperCase = countries.map(function(country){
- let countryCode = country.toUpperCase().slice(0, 3)
- let country = country.length
- return []
-})
+const countriesToUpperCase = countries.map(country => country.toUpperCase())
console.log(countriesToUpperCase)
-// ['ALBANIA', 'BOLIVIA', 'CANADA', 'DENMARK', 'ETHIOPIA', 'FINLAND', 'GERMANY', 'HUNGARY', 'IRELAND', 'JAPAN', 'KENYA']
+
/*
// Arrow function
const countriesToUpperCase = countries.map((country) => {
@@ -255,24 +293,59 @@ const countriesToUpperCase = countries.map((country) => {
//Explicit return arrow function
const countriesToUpperCase = countries.map(country => country.toUpperCase());
*/
+```
+
+```sh
+['ALBANIA', 'BOLIVIA', 'CANADA', 'DENMARK', 'ETHIOPIA', 'FINLAND', 'GERMANY', 'HUNGARY', 'IRELAND', 'JAPAN', 'KENYA']
+```
+
+```js
+const countriesFirstThreeLetters = countries.map(country =>
+ country.toUpperCase().slice(0, 3)
+)
+```
+```sh
+Β ["ALB", "BOL", "CAN", "DEN", "ETH", "FIN", "GER", "HUN", "IRE", "JAP", "KEN"]
```
### filter
-*Filter*: Filter out items which full fill filtering conditions
+_Filter_: Filter out items which full fill filtering conditions and return a new array.
```js
//Filter countries containing land
-const countriesContainingLand = countries.filter(country => country.includes('land'));
-console.log(countriesContainingLand ) //['Finland', 'Ireland']
+const countriesContainingLand = countries.filter(country =>
+ country.includes('land')
+)
+console.log(countriesContainingLand)
+```
-const countriesEndsByia = countries.filter(country => country.includes('ia'));
-console.log(countriesEndsByia) //['Albania', 'Bolivia','Ethiopia']
+```sh
+['Finland', 'Ireland']
+```
+
+```js
+const countriesEndsByia = countries.filter(country => country.includes('ia'))
+console.log(countriesEndsByia)
+```
+
+```sh
+['Albania', 'Bolivia','Ethiopia']
+```
+
+```js
+const countriesHaveFiveLetters = countries.filter(
+ country => country.length === 5
+)
+console.log(countriesHaveFiveLetters)
+```
-const countriesHaveFiveLetters = countries.filter(country => country.length === 5);
-console.log(countriesHaveFiveLetters ) // Β ['Japan', 'Kenya']
+```sh
+['Japan', 'Kenya']
+```
+```js
const scores = [
{ name: 'Asabeneh', score: 95 },
{ name: 'Mathias', score: 80 },
@@ -281,56 +354,81 @@ const scores = [
{ name: 'John', score: 100 }
]
-const scoresGreaterEight = scores.filter((score) => score.score > 80)
-console.log(scoresGreaterEight) //[{name: 'Asabeneh', score: 95}, {name: 'Martha', score: 85},{name: 'John', score: 100}]
+const scoresGreaterEight = scores.filter(score => score.score > 80)
+console.log(scoresGreaterEight)
+```
+
+```sh
+[{name: 'Asabeneh', score: 95}, {name: 'Martha', score: 85},{name: 'John', score: 100}]
```
### reduce
-*reduce*: Reduce takes a callback function. The call back function takes accumulator and current value as a parameter and returns a single value:
+_reduce_: Reduce takes a callback function. The call back function takes accumulator and current value as a parameter and returns a single value:
```js
- const numbers = [1,2,3,4,5];
- const sum = numbers.reduce((accum, curr)=> accum + curr)
+const numbers = [1, 2, 3, 4, 5]
+const sum = numbers.reduce((accum, curr) => accum + curr)
- console.log(sum) //15
+console.log(sum)
+```
+
+```js
+15
```
### every
-*every*: Check if all the elements are similar in one aspect. It returns boolean
+_every_: Check if all the elements are similar in one aspect. It returns boolean
```js
const names = ['Asabeneh', 'Mathias', 'Elias', 'Brook']
-const areAllStr = names.every((name) => typeof name ==='string');
-console.log(arrAllStr) // true;
+const areAllStr = names.every(name => typeof name === 'string')
+
+console.log(arrAllStr)
+```
+
+```sh
+true
```
```js
-const areAllTrue = [true, true, true, true]
-const areAllTrue = bools.every((b)=> {
- return b === true;
+const bools = [true, true, true, true]
+const areAllTrue = bools.every(b => {
+ return b === true
})
console.log(areAllTrue) //true
```
+```sh
+true
+
+```
+
### find
-*find*: Return the first element which satisfies the condition
+_find_: Return the first element which satisfies the condition
```js
+const ages = [24, 22, 25, 32, 35, 18]
+const age = ages.find(age => age < 20)
+
+console.log(age)
+```
-const ages = [24, 22,25,32,35,18];
-const age = ages.find((age) => age < 20)
-console.log(age) // 18
+```js
+18
```
```js
const names = ['Asabeneh', 'Mathias', 'Elias', 'Brook']
-const result = names.find(name => name.length > 7)
-console.log(result) // Asabeneh
+const result = names.find(name => name.length > 7)
+console.log(result)
+```
+```sh
+Asabeneh
```
```js
@@ -342,50 +440,55 @@ const scores = [
{ name: 'John', score: 100 }
]
-const score = scores.find((user) => {
+const score = scores.find(user => {
return user.score > 80
})
-console.log(score) // { name: "Asabeneh", score: 95 }
+console.log(score)
```
-### some
+```sh
+{ name: "Asabeneh", score: 95 }
+```
-*some*: Check if some of the elements are similar in one aspect. It returns boolean
+### findIndex
+
+_findIndex_: Return the position of the first element which satisfies the condition
```js
const names = ['Asabeneh', 'Mathias', 'Elias', 'Brook']
-const bools = [true, true, true, true]
-
-const areSomeTrue = bools.some((b)=> {
- return b === true;
-})
+const ages = [24, 22, 25, 32, 35, 18]
-console.log(areSomeTrue) //true
-```
+const result = names.findIndex(name => name.length > 7)
+console.log(result) // 0
-```js
-const areAllStr = names.some((name) => typeof name ==='number');
-console.log(areAllStr ) // false
+const age = ages.findIndex(age => age < 20)
+console.log(age) // 5
```
-### findIndex
+### some
-*findIndex*: Return the position of the first element which satisfies the condition
+_some_: Check if some of the elements are similar in one aspect. It returns boolean
```js
const names = ['Asabeneh', 'Mathias', 'Elias', 'Brook']
-const ages = [24, 22,25,32,35,18]
+const bools = [true, true, true, true]
-const result = names.findIndex(name => name.length > 7)
-console.log(result) // 0
+const areSomeTrue = bools.some(b => {
+ return b === true
+})
-const age = ages.findIndex((age) => age < 20)
-console.log(age) // 5
+console.log(areSomeTrue) //true
+```
+
+```js
+const areAllStr = names.some(name => typeof name === 'number')
+console.log(areAllStr) // false
```
+
### sort
-*sort*: The sort methods arranges the array elements either ascending or descending order. By default, the ***sort()*** method sorts values as strings.This works well for string array items but not for numbers. If number values are sorted as strings and it give us wrong result. Sort method modify the original array. It is recommended to copy the original document before you start sorting.
+_sort_: The sort methods arranges the array elements either ascending or descending order. By default, the **_sort()_** method sorts values as strings.This works well for string array items but not for numbers. If number values are sorted as strings and it give us wrong result. Sort method modify the original array. It is recommended to copy the original data before you start using _sort_ method.
#### Sorting string values
@@ -395,21 +498,22 @@ console.log(products.sort()) // ['Apple', 'Carrot', 'Coffee', 'Honey', 'Milk', '
//Now the original products array is also sorted
```
-#### Sorting Numeric values
+#### Sorting Numeric values
-As you can see in the example below, 100 came first after sorted in ascending order. Sort converts items to string , since '100' and other numbers compared, 1 which the beginning of the string '100' became the smallest. To avoid this, we use a compare call back function inside the sort method, which return a negative, zero or positive.
+As you can see in the example below, 100 came first after sorted in ascending order. Sort converts items to string , since '100' and other numbers compared, 1 which the beginning of the string '100' became the smallest. To avoid this, we use a compare call back function inside the sort method, which return a negative, zero or positive.
```js
const numbers = [9.81, 3.14, 100, 37]
// Using sort method to sort number items provide a wrong result. see below
console.log(numbers.sort()) //[100, 3.14, 37, 9.81]
numbers.sort(function(a, b) {
-return a - b
+ return a - b
})
console.log(numbers) // [3.14, 9.81, 37, 100]
+
numbers.sort(function(a, b) {
-return b - a
+ return b - a
})
console.log(numbers) //[100, 37, 9.81, 3.14]
```
@@ -422,35 +526,43 @@ When ever we sort objects in an array. We use the object key to compare. Lets se
objArr.sort(function(a, b) {
if (a.key < b.key) return -1
if (a.key > b.key) return 1
- return 0;
+ return 0
})
// or
objArr.sort(function(a, b) {
- if (a['key'] < b['key']) return -1;
- if (a['key'] > b['key']) return 1;
- return 0;
+ if (a['key'] < b['key']) return -1
+ if (a['key'] > b['key']) return 1
+ return 0
})
-const users = [{name:'Asabeneh', age:150}, {name:'Brook', age:50}, {name:'Eyo', age:100},{name:'Elias', age:22}];
+const users = [
+ { name: 'Asabeneh', age: 150 },
+ { name: 'Brook', age: 50 },
+ { name: 'Eyo', age: 100 },
+ { name: 'Elias', age: 22 }
+]
users.sort((a, b) => {
- if (a.age < b.age) return -1;
- if (a.age > b.age) return 1;
- return 0;
-});
-console.log(users); // sorted ascending
+ if (a.age < b.age) return -1
+ if (a.age > b.age) return 1
+ return 0
+})
+console.log(users) // sorted ascending
//[{β¦}, {β¦}, {β¦}, {β¦}]
```
-π You are doing great.Never give up because great things take time. You have just completed day 9 challenges and you are 9 steps a head in to your way to greatness. Now do some exercises for your brain and for your muscle.
+
+π You are doing great.Never give up because great things take time. You have just completed day 9 challenges and you are 9 steps a head in to your way to greatness. Now do some exercises for your brain and for your muscle.
## π» Exercises
+### Exercises: Level 1
+
```js
- const countries = ['Finland', 'Sweden', 'Denmark', 'Norway', 'IceLand'];
- const names = ['Asabeneh', 'Mathias', 'Elias', 'Brook'];
- const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
- const products = [
+const countries = ['Finland', 'Sweden', 'Denmark', 'Norway', 'IceLand']
+const names = ['Asabeneh', 'Mathias', 'Elias', 'Brook']
+const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
+const products = [
{ product: 'banana', price: 3 },
{ product: 'mango', price: 6 },
{ product: 'potato', price: ' ' },
@@ -460,41 +572,47 @@ console.log(users); // sorted ascending
]
```
-1. Explain the difference between ***forEach, map, filter, and reduce***.
+1. Explain the difference between **_forEach, map, filter, and reduce_**.
2. Define a call function before you them in forEach, map, filter or reduce.
-3. Use ***forEach*** to console.log each country in the countries array.
-4. Use ***forEach*** to console.log each name in the names array.
-5. Use ***forEach*** to console.log each number in the numbers array.
-6. Use ***map*** to create a new array by changing each country to uppercase in the countries array.
-7. Use ***map*** to create an array of countries length from countries array.
-8. Use ***map*** to create a new array by changing each number to square in the numbers array
-9. Use ***map*** to change to each name to uppercase in the names array
-10. Use ***map*** to map the products array to its corresponding prices.
-11. Use ***filter*** to filter out countries containing ***land***.
-12. Use ***filter*** to filter out countries having six character.
-13. Use ***filter*** to filter out countries containing six letters and more in the country array.
-14. Use ***filter*** to filter out country start with 'E';
-15. Use ***filter*** to filter out only prices with values.
-16. Find the total price of products by chaining two or more array iterators(eg. arr.map(callback).filter(callback).reduce(callback))
-17. Find the sum of price of products using only reduce reduce(callback))
+3. Use **_forEach_** to console.log each country in the countries array.
+4. Use **_forEach_** to console.log each name in the names array.
+5. Use **_forEach_** to console.log each number in the numbers array.
+6. Use **_map_** to create a new array by changing each country to uppercase in the countries array.
+7. Use **_map_** to create an array of countries length from countries array.
+8. Use **_map_** to create a new array by changing each number to square in the numbers array
+9. Use **_map_** to change to each name to uppercase in the names array
+10. Use **_map_** to map the products array to its corresponding prices.
+11. Use **_filter_** to filter out countries containing **_land_**.
+12. Use **_filter_** to filter out countries having six character.
+13. Use **_filter_** to filter out countries containing six letters and more in the country array.
+14. Use **_filter_** to filter out country start with 'E';
+15. Use **_filter_** to filter out only prices with values.
18. Declare a function called getStringLists which takes an array as a parameter and then returns an array only with string items.
-19. Use ***reduce*** to sum all the numbers in the numbers array.
-20. Use ***reduce*** to concatenate all the countries and to produce this sentence: ***Estonia, Finland, Sweden, Denmark, Norway, and IceLand are north European countries***
-21. Explain the difference between ***some*** and ***every***
-22. Use ***some*** to check if some names' length greater than seven in names array
-23. Use ***every*** to check if all the countries contain the word land
-24. Explain the difference between ***find*** and ***findIndex***.
-25. Use ***find*** to find the first country containing only six letters in the countries array
-26. Use ***findIndex*** to find the position of the first country containing only six letters in the countries array
-27. Use ***findIndex*** to find the position of ***Norway*** if it doesn't exist in the array you will get -1.
-28. Use ***findIndex*** to find the position of ***Russia*** if it doesn't exist in the array you will get -1.
-29. Declare a function called ***categorizeCountries*** which returns an array of countries which have some common pattern(you find the countries array in this repository as countries.js(eg 'land', 'ia', 'island','stan')).
-30. Create a function which return an array of objects, which is the letter and the number of times the letter use to start with a name of a country.
-31. Declare a ***getFirstTenCountries*** function and return an array of ten countries. Use different functional programming to work on the countries.js array
-32. Declare a ***getLastTenCountries*** function which which returns the last ten countries in the countries array.
-33. Find out which *letter* is used many *times* as initial for a country name from the countries array (eg. Finland, Fiji, France etc)
-34. Use the countries information, in the data folder. Sort countries by name, by capital, by population
-35. \*\*\* Find the 10 most spoken languages:
+19. Use **_reduce_** to sum all the numbers in the numbers array.
+20. Use **_reduce_** to concatenate all the countries and to produce this sentence: **_Estonia, Finland, Sweden, Denmark, Norway, and IceLand are north European countries_**
+21. Explain the difference between **_some_** and **_every_**
+22. Use **_some_** to check if some names' length greater than seven in names array
+23. Use **_every_** to check if all the countries contain the word land
+24. Explain the difference between **_find_** and **_findIndex_**.
+25. Use **_find_** to find the first country containing only six letters in the countries array
+26. Use **_findIndex_** to find the position of the first country containing only six letters in the countries array
+27. Use **_findIndex_** to find the position of **_Norway_** if it doesn't exist in the array you will get -1.
+28. Use **_findIndex_** to find the position of **_Russia_** if it doesn't exist in the array you will get -1.
+
+### Exercises: Level 2
+
+1. Find the total price of products by chaining two or more array iterators(eg. arr.map(callback).filter(callback).reduce(callback))
+1. Find the sum of price of products using only reduce reduce(callback))
+1. Declare a function called **_categorizeCountries_** which returns an array of countries which have some common pattern(you find the countries array in this repository as countries.js(eg 'land', 'ia', 'island','stan')).
+1. Create a function which return an array of objects, which is the letter and the number of times the letter use to start with a name of a country.
+1. Declare a **_getFirstTenCountries_** function and return an array of ten countries. Use different functional programming to work on the countries.js array
+1. Declare a **_getLastTenCountries_** function which which returns the last ten countries in the countries array.
+1. Find out which _letter_ is used many _times_ as initial for a country name from the countries array (eg. Finland, Fiji, France etc)
+
+### Exercises: Level 3
+
+1. Use the countries information, in the data folder. Sort countries by name, by capital, by population
+1. \*\*\* Find the 10 most spoken languages:
````js
// Your output should look like this
@@ -519,67 +637,68 @@ console.log(users); // sorted ascending
(25, 'Arabic')
]```
-36. \*\*\* Use countries_data.js file create a function which create the ten most populated countries
-
- ````js
- console.log(mostPopulatedCountries(countries, 10))
-
- [
- {country: 'China', population: 1377422166},
- {country: 'India', population: 1295210000},
- {country: 'United States of America', population: 323947000},
- {country: 'Indonesia', population: 258705000},
- {country: 'Brazil', population: 206135893},
- {country: 'Pakistan', population: 194125062},
- {country: 'Nigeria', population: 186988000},
- {country: 'Bangladesh', population: 161006790},
- {country: 'Russian Federation', population: 146599183},
- {country: 'Japan', population: 126960000}
- ]
-
- console.log(mostPopulatedCountries(countries, 3))
- [
- {country: 'China', population: 1377422166},
- {country: 'India', population: 1295210000},
- {country: 'United States of America', population: 323947000}
- ]```
-
- ````
-
-37. \*\*\* Try to develop a program which calculate measure of central tendency of a sample(mean, median, mode) and measure of variability(range, variance, standard deviation). In addition to those measures find the min, max, count, percentile, and frequency distribution of the sample. You can create an object called statistics and create all the functions which do statistical calculations as method for the statistics object. Check the output below.
-
- ```js
- const ages = [31, 26, 34, 37, 27, 26, 32, 32, 26, 27, 27, 24, 32, 33, 27, 25, 26, 38, 37, 31, 34, 24, 33, 29, 26]
-
- console.log('Count:', statistics.count()) // 25
- console.log('Sum: ', statistics.sum()) // 744
- console.log('Min: ', statistics.min()) // 24
- console.log('Max: ', statistics.max()) // 38
- console.log('Range: ', statistics.range() // 14
- console.log('Mean: ', statistics.mean()) // 30
- console.log('Median: ',statistics.median()) // 29
- console.log('Mode: ', statistics.mode()) // {'mode': 26, 'count': 5}
- console.log('Variance: ',statistics.var()) // 17.5
- console.log('Standard Deviation: ', statistics.std()) // 4.2
- console.log('Variance: ',statistics.var()) // 17.5
- console.log('Frequency Distribution: ',statistics.freqDist()) # [(20.0, 26), (16.0, 27), (12.0, 32), (8.0, 37), (8.0, 34), (8.0, 33), (8.0, 31), (8.0, 24), (4.0, 38), (4.0, 29), (4.0, 25)]
- ```
-
- ```sh
- console.log(statistics.describe())
- Count: 25
- Sum: 744
- Min: 24
- Max: 38
- Range: 14
- Mean: 30
- Median: 29
- Mode: (26, 5)
- Variance: 17.5
- Standard Deviation: 4.2
- Frequency Distribution: [(20.0, 26), (16.0, 27), (12.0, 32), (8.0, 37), (8.0, 34), (8.0, 33), (8.0, 31), (8.0, 24), (4.0, 38), (4.0, 29), (4.0, 25)]
- ```
+ ````
+
+1. \*\*\* Use countries_data.js file create a function which create the ten most populated countries
+
+ ````js
+ console.log(mostPopulatedCountries(countries, 10))
+
+ [
+ {country: 'China', population: 1377422166},
+ {country: 'India', population: 1295210000},
+ {country: 'United States of America', population: 323947000},
+ {country: 'Indonesia', population: 258705000},
+ {country: 'Brazil', population: 206135893},
+ {country: 'Pakistan', population: 194125062},
+ {country: 'Nigeria', population: 186988000},
+ {country: 'Bangladesh', population: 161006790},
+ {country: 'Russian Federation', population: 146599183},
+ {country: 'Japan', population: 126960000}
+ ]
+
+ console.log(mostPopulatedCountries(countries, 3))
+ [
+ {country: 'China', population: 1377422166},
+ {country: 'India', population: 1295210000},
+ {country: 'United States of America', population: 323947000}
+ ]
+ ```
+
+1. \*\*\* Try to develop a program which calculate measure of central tendency of a sample(mean, median, mode) and measure of variability(range, variance, standard deviation). In addition to those measures find the min, max, count, percentile, and frequency distribution of the sample. You can create an object called statistics and create all the functions which do statistical calculations as method for the statistics object. Check the output below.
+
+ ```js
+ const ages = [31, 26, 34, 37, 27, 26, 32, 32, 26, 27, 27, 24, 32, 33, 27, 25, 26, 38, 37, 31, 34, 24, 33, 29, 26]
+
+ console.log('Count:', statistics.count()) // 25
+ console.log('Sum: ', statistics.sum()) // 744
+ console.log('Min: ', statistics.min()) // 24
+ console.log('Max: ', statistics.max()) // 38
+ console.log('Range: ', statistics.range() // 14
+ console.log('Mean: ', statistics.mean()) // 30
+ console.log('Median: ',statistics.median()) // 29
+ console.log('Mode: ', statistics.mode()) // {'mode': 26, 'count': 5}
+ console.log('Variance: ',statistics.var()) // 17.5
+ console.log('Standard Deviation: ', statistics.std()) // 4.2
+ console.log('Variance: ',statistics.var()) // 17.5
+ console.log('Frequency Distribution: ',statistics.freqDist()) # [(20.0, 26), (16.0, 27), (12.0, 32), (8.0, 37), (8.0, 34), (8.0, 33), (8.0, 31), (8.0, 24), (4.0, 38), (4.0, 29), (4.0, 25)]
+ ```
+
+ ```sh
+ console.log(statistics.describe())
+ Count: 25
+ Sum: 744
+ Min: 24
+ Max: 38
+ Range: 14
+ Mean: 30
+ Median: 29
+ Mode: (26, 5)
+ Variance: 17.5
+ Standard Deviation: 4.2
+ Frequency Distribution: [(20.0, 26), (16.0, 27), (12.0, 32), (8.0, 37), (8.0, 34), (8.0, 33), (8.0, 31), (8.0, 24), (4.0, 38), (4.0, 29), (4.0, 25)]
+ ```
π CONGRATULATIONS ! π
-
-[<< Day 8](https://github.com/Asabeneh/30DaysOfJavaScript/blob/master/08_Day/08_day_objects.md) | [Day 10 >>](#)
+
+[<< Day 8](https://github.com/Asabeneh/30DaysOfJavaScript/blob/master/08_Day/08_day_objects.md) | [Day 10 >>](https://github.com/Asabeneh/30DaysOfJavaScript/blob/master/10_Day/10_day_Set_and_Map.md)
diff --git a/10_Day/10_day_Set_and_Map.md b/10_Day/10_day_Set_and_Map.md
new file mode 100644
index 0000000..ed0f3ea
--- /dev/null
+++ b/10_Day/10_day_Set_and_Map.md
@@ -0,0 +1,441 @@
+
+
+[<< Day 9](https://github.com/Asabeneh/30DaysOfJavaScript/blob/master/09_Day/09_day_higher_order_functions.md) | [Day 11>>](https://github.com/Asabeneh/30DaysOfJavaScript/blob/master/11_Day/11_destructuring_and_spread.md)
+
+
+
+- [Day 10](#day-10)
+ - [Set](#set)
+ - [Creating an empty set](#creating-an-empty-set)
+ - [Creating set from array](#creating-set-from-array)
+ - [Adding an element to a set](#adding-an-element-to-a-set)
+ - [Deleting an element a set](#deleting-an-element-a-set)
+ - [Checking an element in the set](#checking-an-element-in-the-set)
+ - [Clearing the set](#clearing-the-set)
+ - [Union of sets](#union-of-sets)
+ - [Intersection of sets](#intersection-of-sets)
+ - [Difference of sets](#difference-of-sets)
+ - [Map](#map)
+ - [Creating an empty Map](#creating-an-empty-map)
+ - [Creating an Map from array](#creating-an-map-from-array)
+ - [Adding values to the Map](#adding-values-to-the-map)
+ - [Getting a value from Map](#getting-a-value-from-map)
+ - [Checking key in Map](#checking-key-in-map)
+ - [Exercises](#exercises)
+ - [Exercises:Level 1](#exerciseslevel-1)
+ - [Exercises:Level 2](#exerciseslevel-2)
+ - [Exercises:Level 3](#exerciseslevel-3)
+
+# Day 10
+
+## Set
+
+Set is a collection a collection of elements. Set can only contains unique elements.
+Lets see how to create a set
+
+### Creating an empty set
+
+```js
+const companies = new Set()
+console.log(companies)
+```
+
+```sh
+{}
+```
+
+### Creating set from array
+
+```js
+const languages = [
+ 'English',
+ 'Finnish',
+ 'English',
+ 'French',
+ 'Spanish',
+ 'English',
+ 'French'
+]
+
+const setOfLangauges = new Set(languages)
+console.log(setOfLangauges)
+```
+
+```sh
+Set(4)Β {"English", "Finnish", "French", "Spanish"}
+```
+
+Set is an iterable object and we can iterate through each elements.
+
+```js
+const languages = [
+ 'English',
+ 'Finnish',
+ 'English',
+ 'French',
+ 'Spanish',
+ 'English',
+ 'French'
+]
+
+const setOfLangauges = new Set(languages)
+
+for (const language of setOfLangauges) {
+ console.log(language)
+}
+```
+
+```sh
+ English
+ Finnish
+ French
+ Spanish
+```
+
+### Adding an element to a set
+
+```js
+const companies = new Set() // creating an empty set
+console.log(companies.size) // 0
+
+companies.add('Google') // add element to the set
+companies.add('Facebook')
+companies.add('Amazon')
+companies.add('Oracle')
+companies.add('Microsoft')
+
+console.log(companies.size) // 5 elements in the set
+console.log(companies)
+```
+
+```sh
+Set(5)Β {"Google", "Facebook", "Amazon", "Oracle", "Microsoft"}
+```
+
+We can also use loop to add element to a set.
+
+```js
+const companies = ['Google', 'Facebook', 'Amazon', 'Oracle', 'Microsoft']
+setOfCompanies = new Set()
+for (const company of companies) {
+ setOfCompanies.add(company)
+}
+```
+
+```sh
+Set(5)Β {"Google", "Facebook", "Amazon", "Oracle", "Microsoft"}
+
+```
+
+### Deleting an element a set
+
+We can delete an element from a set using a delete method.
+
+```js
+console.log(companies.delete('Google'))
+console.log(companies.size) // 4 elements left in the set
+```
+
+### Checking an element in the set
+
+The has method can help to know if a certain element exists in a set.
+
+```js
+console.log(companies.has('Apple')) // false
+console.log(companies.has('Facebook')) // true
+```
+
+### Clearing the set
+
+It removes all the elements from a set.
+
+```js
+companies.clear()
+
+console.log(companies)
+```
+
+```sh
+{}
+
+```
+
+See the example below to learn how to use set.
+
+```js
+const languages = [
+ 'English',
+ 'Finnish',
+ 'English',
+ 'French',
+ 'Spanish',
+ 'English',
+ 'French'
+]
+const langSet = new Set(languages)
+console.log(langSet) // Set(4)Β {"English", "Finnish", "French", "Spanish"}
+console.log(langSet.size) // 4
+
+const counts = []
+const count = {}
+
+for (const l of langSet) {
+ const filteredLang = languages.filter(lng => lng === l)
+ console.log(filteredLang) // ["English", "English", "English"]
+ counts.push({ lang: l, count: filteredLang.length })
+}
+console.log(counts)
+```
+
+```js
+[
+ { lang: 'English', count: 3 },
+ { lang: 'Finnish', count: 1 },
+ { lang: 'French', count: 2 },
+ { lang: 'Spanish', count: 1 }
+]
+```
+
+Other use case of set. For instance to count unique item in an array.
+
+```js
+const numbers = [5, 3, 2, 5, 5, 9, 4, 5]
+const setOfNumbers = new Set(numbers)
+
+console.log(setOfNumbers)
+```
+
+```sh
+Set(5)Β {5, 3, 2, 9, 4}
+```
+
+### Union of sets
+
+To find a union to two sets can be achieved using spread operator. Lets find the union of set A and set B (A U B)
+
+```js
+let a = [1, 2, 3, 4, 5]
+let b = [3, 4, 5, 6]
+let c = [...a, ...b]
+
+let A = new Set(a)
+let B = new Set(b)
+let C = new Set(c)
+
+console.log(C)
+```
+
+```sh
+Set(6)Β {1, 2, 3, 4, 5,6}
+
+```
+
+### Intersection of sets
+
+To find an intersection of two sets can be achieved using filter. Lets find the union of set A and set B (A β© B)
+
+```js
+let a = [1, 2, 3, 4, 5]
+let b = [3, 4, 5, 6]
+
+let A = new Set(a)
+let B = new Set(b)
+
+let c = a.filter(num => B.has(num))
+let C = new Set(c)
+
+console.log(C)
+```
+
+```sh
+Set(3)Β {3, 4, 5}
+
+```
+
+### Difference of sets
+
+To find an the difference between two sets can be achieved using filter. Lets find the different of set A and set B (A \ B)
+
+```js
+let a = [1, 2, 3, 4, 5]
+let b = [3, 4, 5, 6]
+
+let A = new Set(a)
+let B = new Set(b)
+
+let c = a.filter(num => !B.has(num))
+let C = new Set(c)
+
+console.log(C)
+```
+
+```sh
+Set(2)Β {1, 2}
+
+```
+
+## Map
+
+### Creating an empty Map
+
+```js
+const map = new Map()
+console.log(map)
+```
+
+```sh
+Map(0)Β {}
+```
+
+### Creating an Map from array
+
+```js
+countries = [
+ ['Finland', 'Helsinki'],
+ ['Sweden', 'Stockholm'],
+ ['Norway', 'Oslo']
+]
+const map = new Map(countries)
+console.log(map)
+console.log(map.size)
+```
+
+```sh
+Map(3)Β {"Finland" => "Helsinki", "Sweden" => "Stockholm", "Norway" => "Oslo"}
+3
+```
+
+### Adding values to the Map
+
+```js
+const countriesMap = new Map()
+console.log(countriesMap.size) // 0
+countriesMap.set('Finland', 'Helsinki')
+countriesMap.set('Sweden', 'Stockholm')
+countriesMap.set('Norway', 'Oslo')
+console.log(countriesMap)
+console.log(countriesMap.size)
+```
+
+```sh
+Map(3)Β {"Finland" => "Helsinki", "Sweden" => "Stockholm", "Norway" => "Oslo"}
+3
+```
+
+### Getting a value from Map
+
+```js
+console.log(countriesMap.get('Finland'))
+```
+
+```sh
+Helsinki
+```
+
+### Checking key in Map
+
+Check if a key exist in a map using *has* method. It returns *true* or *false*.
+
+```js
+console.log(countriesMap.has('Finland'))
+```
+
+```sh
+true
+```
+
+Getting all values from map using loop
+
+```js
+for (const country of countriesMap) {
+ console.log(country)
+}
+```
+
+```sh
+(2)Β ["Finland", "Helsinki"]
+(2)Β ["Sweden", "Stockholm"]
+(2)Β ["Norway", "Oslo"]
+```
+
+```sh
+for (const [country, city] of countriesMap){
+console.log(country, city)
+}
+```
+
+```sh
+Finland Helsinki
+Sweden Stockholm
+Norway Oslo
+```
+
+π You established a big milestone, you are unstoppable. Keep going! You have just completed day 10 challenges and you are 10 steps a head in to your way to greatness. Now do some exercises for your brain and for your muscle.
+
+## Exercises
+
+### Exercises:Level 1
+```js
+const a = {4, 5, 8, 9}
+const b = {3, 4, 5, 7}
+const countries = ['Finland', 'Sweden', 'Norway']
+```
+
+1. create an empty set
+2. Create a set containing 0 to 10 using loop
+3. Remove an element from a set
+4. Clear a set
+5. Create a set of 5 string elements from array
+6. Create a map of countries and number of characters of a country
+
+### Exercises:Level 2
+
+1. Find a union b
+2. Find a intersection b
+3. Find a with b
+
+### Exercises:Level 3
+
+1. \*\*\* Use the countries data to find the 10 most spoken languages:
+
+ ````js
+ // Your output should look like this
+ console.log(mostSpokenLanguages(countries, 10))
+ [(91, 'English'),
+ (45, 'French'),
+ (25, 'Arabic'),
+ (24, 'Spanish'),
+ (9, 'Russian'),
+ (9, 'Portuguese'),
+ (8, 'Dutch'),
+ (7, 'German'),
+ (5, 'Chinese'),
+ (4, 'Swahili'),
+ (4, 'Serbian')]
+
+ // Your output should look like this
+ console.log(mostSpokenLanguages(countries, 3))
+ [
+ (91, 'English'),
+ (45, 'French'),
+ (25, 'Arabic')
+ ]```
+
+ ````
+
+π CONGRATULATIONS ! π
+
+[<< Day 9](https://github.com/Asabeneh/30DaysOfJavaScript/blob/master/09_Day/09_day_higher_order_functions.md) | [Day 11>>](https://github.com/Asabeneh/30DaysOfJavaScript/blob/master/11_Day/11_destructuring_and_spread.md)
diff --git a/11_Day/11_destructuring_and_spread.md b/11_Day/11_destructuring_and_spread.md
new file mode 100644
index 0000000..124302a
--- /dev/null
+++ b/11_Day/11_destructuring_and_spread.md
@@ -0,0 +1,693 @@
+
+
+[<< Day 10](https://github.com/Asabeneh/30DaysOfJavaScript/blob/master/09_Day/09_day_Set_and_Map.md) | [Day 12>>](#)
+
+
+
+- [Day 11](#day-11)
+ - [Destructuring and Spread](#destructuring-and-spread)
+ - [Destructing Arrays](#destructing-arrays)
+ - [Destructuring during iteration](#destructuring-during-iteration)
+ - [Destructuring Object](#destructuring-object)
+ - [Renaming during structuring](#renaming-during-structuring)
+ - [Object parameter without destructuring](#object-parameter-without-destructuring)
+ - [Object parameter with destructuring](#object-parameter-with-destructuring)
+ - [Destructuring object during iteration](#destructuring-object-during-iteration)
+ - [Spread or Rest Operator](#spread-or-rest-operator)
+ - [Spread operator to get the rest of array elements](#spread-operator-to-get-the-rest-of-array-elements)
+ - [Spread operator to copy array](#spread-operator-to-copy-array)
+ - [Spread operator to copy object](#spread-operator-to-copy-object)
+ - [Spread operator with arrow function](#spread-operator-with-arrow-function)
+ - [Exercises](#exercises)
+ - [Exercises: Level 1](#exercises-level-1)
+ - [Exercises: Level 2](#exercises-level-2)
+ - [Exercises: Level 3](#exercises-level-3)
+
+# Day 11
+
+## Destructuring and Spread
+
+Destructuring is a way to unpack arrays, and objects and assigning to a distinct variable.
+
+### Destructing Arrays
+
+```js
+ const numbers = [1, 2, 3]
+ let [numOne, numTwo, numThree] = numbers
+
+ console.log(numOne, numTwo, numThree)
+```
+
+```sh
+ 1 2 3
+```
+
+```js
+ const names = ['Asabeneh', 'Brook', 'David', 'John']
+ let [firstPerson, secondPerson, ThirdPerson, fourth Person] = names
+
+ console.log(firstName, secondPerson,thirdPerson, fourthPerson)
+```
+
+```sh
+Asabeneh Brook David John
+```
+
+```js
+ const scientificConstants = [2.72, 3.14, 9.81, 37, 100]
+ let [e, pi, gravity, bodyTemp, boilingTemp] = scientificConstants
+
+ console.log(e,pi,gravity, bodyTemp, boilingTemp)
+```
+
+```sh
+2.72 3.14 9.81 37 100
+```
+
+```js
+const fullStack = [
+ ['HTML', 'CSS', 'JS', 'React'],
+ ['Node', 'Express', 'MongoDB']
+]
+const [frontEnd, backEnd] = fullStack
+
+console.log(frontEnd)
+console.log(backEnd)
+```
+
+```sh
+["HTML", "CSS", "JS", "React"]
+["Node", "Express", "MongoDB"]
+```
+
+If we like to skip on of the values in the array we use additional comma. The comma helps to omit the value at that specific index
+
+```js
+ const numbers = [1, 2, 3]
+ let [numOne, , numThree] = numbers //2 is omitted
+
+ console.log(numOne, numThree)
+```
+
+```sh
+1 3
+```
+
+```js
+ const names = ['Asabeneh', 'Brook', 'David', 'John']
+ let [, secondPerson, , fourth Person] = name // first and third person is omitted
+
+ console.log(secondPerson, fourthPerson)
+```
+
+```sh
+Brook John
+```
+
+We can use default value in case the value of array for that index is undefined:
+
+```js
+const names = [undefined, 'Brook', 'David']
+let [
+ firstPerson = 'Asabeneh',
+ secondPerson,
+ thirdPerson,
+ fourthPerson = 'John'
+] = names
+
+console.log(firstPerson, secondPerson, thirdPerson, fourthPerson)
+```
+
+```sh
+Asabeneh Brook David John
+```
+
+We can not assign variable to all the elements in the array. We can destructure few of the first and we can get the remaining as array using spread operator(...).
+
+```js
+const nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
+let [num1, num2, num3, ...rest] = nums
+
+console.log(num1, num2, num3)
+console.log(rest)
+```
+
+```sh
+1 2 3
+[4, 5, 6, 7, 8, 9, 10]
+```
+
+### Destructuring during iteration
+
+```js
+const countries = [['Finland', 'Helsinki'], ['Sweden', 'Stockholm'], ['Norway', 'Oslo']]
+
+for (const [country, city] of countries) {
+console.log(country, city)
+}
+```
+
+```sh
+Finland Helsinki
+Sweden Stockholm
+Norway Oslo
+```
+
+```js
+const fullStack = [
+ ['HTML', 'CSS', 'JS', 'React'],
+ ['Node', 'Express', 'MongoDB']
+]
+
+for(const [first, second, third] of fullStack) {
+console.log(first, second, third)
+}
+```
+
+```sh
+HTML CSS JS
+Node Express MongoDB
+```
+
+### Destructuring Object
+
+When we destructure the name of the variable we use to destructure should be exactly the same as the key or property of the object. See the example below.
+
+```js
+const rectangle = {
+ width: 20,
+ height: 10,
+ area: 200
+}
+let { width, height, area, perimeter } = rectangle
+
+console.log(width, height, area, perimeter)
+```
+
+```sh
+20 10 200 undefined
+```
+
+### Renaming during structuring
+
+```js
+const rectangle = {
+ width: 20,
+ height: 10,
+ area: 200
+}
+let { width: w, heigh: h, area: a, perimeter: p } = rectangle
+
+console.log(w, h, a, p)
+```
+
+```sh
+20 10 200 undefined
+```
+
+If the key is not found in the object the variable will be assigned to undefined. In case, the key is not in the object we can give a default value during declaration. See the example.
+
+```js
+const rectangle = {
+ width: 20,
+ height: 10,
+ area: 200
+}
+let { width, heigh, area, perimeter = 60 } = rectangle
+
+console.log(width, height, area, perimeter) //20 10 200 60
+//Lets modify the object:width to 30 and perimeter to 80
+```
+
+```js
+const rectangle = {
+ width: 30,
+ height: 10,
+ area: 200,
+ perimeter: 80
+}
+let { width, heigh, area, perimeter = 60 } = rectangle
+console.log(width, height, area, perimeter) //20 10 200 80
+```
+
+Destructuring keys as a function parameters. Lets create a function which take a rectangle object and it return a perimeter of a rectangle.
+
+### Object parameter without destructuring
+
+```js
+// Without destructuring
+const rect = {
+ width: 20,
+ height: 10
+}
+const calculatePerimeter = rectangle => {
+ return 2 * (rectangle.width + rectangle.height)
+}
+
+console.log(calculatePerimeter(rect)) // 60
+//with destructuring
+```
+
+```js
+//Another Example
+const person = {
+ firstName: 'Asabeneh',
+ lastName: 'Yetayeh',
+ age: 250,
+ country: 'Finland',
+ job: 'Instructor and Developer',
+ skills: [
+ 'HTML',
+ 'CSS',
+ 'JavaScript',
+ 'React',
+ 'Redux',
+ 'Node',
+ 'MongoDB',
+ 'Python',
+ 'D3.js'
+ ],
+ languages: ['Amharic', 'English', 'Suomi(Finnish)']
+}
+// Lets create a function which give information about the person object without destructuring
+
+const getPersonInfo = obj => {
+ const skills = obj.skills
+ const formattedSkills = skills.slice(0, -1).join(', ')
+ const languages = obj.languages
+ const formattedLanguages = languages.slice(0, -1).join(', ')
+
+ personInfo = `${obj.firstName} ${obj.lastName} lives in ${obj.country}. He is ${
+ obj.age
+ } years old. He is an ${obj.job}. He teaches ${formattedSkills} and ${
+ skills[skills.length - 1]
+ }. He speaks ${formattedLanguages} and a little bit of ${languages[2]}.`
+
+ return personInfo
+}
+
+console.log(getPersonInfo(person))
+```
+
+### Object parameter with destructuring
+
+```js
+
+const calculatePerimeter = ({ width, height }) => {
+ return 2 * (width + height)
+}
+
+console.log(calculatePerimeter(rect)) // 60
+```
+
+```js
+// Lets create a function which give information about the person object with destructuring
+const getPersonInfo = ({
+ firstName,
+ lastName,
+ age,
+ country,
+ job,
+ skills,
+ languages
+}) => {
+ const formattedSkills = skills.slice(0, -1).join(', ')
+ const formattedLanguages = languages.slice(0, -1).join(', ')
+
+ personInfo = `${firstName} ${lastName} lives in ${country}. He is ${age} years old. He is an ${job}. He teaches ${formattedSkills} and ${
+ skills[skills.length - 1]
+ }. He speaks ${formattedLanguages} and a little bit of ${languages[2]}.`
+
+ return personInfo
+}
+console.log(getPersonInfo(person))
+/*
+Asabeneh Yetayeh lives in Finland. He is 200 years old. He is an Instructor and Developer. He teaches HTML, CSS, JavaScript, React, Redux, Node, MongoDB, Python and D3.js. He speaks Amharic, English and a little bit of Suomi(Finnish)
+*/
+```
+
+### Destructuring object during iteration
+
+```js
+const todoList = [
+{
+ task:'Prepare JS Test',
+ time:'4/1/2020 8:30',
+ completed:true
+},
+{
+ task:'Give JS Test',
+ time:'4/1/2020 10:00',
+ completed:false
+},
+{
+ task:'Assess Test Result',
+ time:'4/1/2020 1:00',
+ completed:false
+}
+]
+
+for (const {task, time, completed} of todoList){
+ console.log(task, time, completed)
+}
+```
+
+```sh
+Prepare JS Test 4/1/2020 8:30 true
+Give JS Test 4/1/2020 10:00 false
+Assess Test Result 4/1/2020 1:00 false
+```
+
+### Spread or Rest Operator
+
+When we destructure an array we use the spread operator(...) to get the rest elements as array. In addition to that we use spread operator to spread arr elements to another array.
+
+### Spread operator to get the rest of array elements
+
+```js
+const nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
+let [num1, num2, num3, ...rest] = nums
+β
+console.log(num1, num2, num3)
+console.log(rest)
+```
+
+```sh
+1 2 3
+[4, 5, 6, 7, 8, 9, 10]
+```
+
+```js
+const countries = [
+ 'Germany',
+ 'France',
+ 'Belgium',
+ 'Finland',
+ 'Sweden',
+ 'Norway',
+ 'Denmark',
+ 'Iceland'
+]
+
+let [gem, fra, , ...nordicCountries] = countries
+
+console.log(gem)
+console.log(fra)
+console.log(nordicCountries)
+```
+
+```sh
+Germany
+France
+["Finland", "Sweden", "Norway", "Denmark", "Iceland"]
+```
+
+### Spread operator to copy array
+
+```js
+const evens = [0, 2, 4, 6, 8, 10]
+const evenNumbers = [...evens]
+
+const odds = [1, 3, 5, 7, 9]
+const oddNumbers = [...odds]
+
+const wholeNumbers = [...evens, ...odds]
+
+console.log(evenNumbers)
+console.log(oddNumbers)
+console.log(wholeNumbers)
+
+
+```
+
+```sh
+[0, 2, 4, 6, 8, 10]
+[1, 3, 5, 7, 9]
+[0, 2, 4, 6, 8, 10, 1, 3, 5, 7, 9]
+```
+
+```js
+const frontEnd = ['HTML', 'CSS', 'JS', 'React']
+const backEnd = ['Node', 'Express', 'MongoDB']
+const fullStack = [...frontEnd, ...backEnd]
+
+console.log(fullStack)
+```
+
+```sh
+["HTML", "CSS", "JS", "React", "Node", "Express", "MongoDB"]
+```
+
+### Spread operator to copy object
+
+We can copy an object using a spread operator
+
+```js
+const user = {
+ name:'Asabeneh',
+ title:'Programmer',
+ country:'Finland',
+ city:'Helsinki'
+}
+
+const copiedUser = {...user}
+console.log(copiedUser)
+```
+
+```sh
+{name: "Asabeneh", title: "Programmer", country: "Finland", city: "Helsinki"}
+```
+
+Modifying or changing the object while copying
+
+```js
+const user = {
+ name:'Asabeneh',
+ title:'Programmer',
+ country:'Finland',
+ city:'Helsinki'
+}
+
+const copiedUser = {...user, title:'instructor'}
+console.log(copiedUser)
+```
+
+```sh
+{name: "Asabeneh", title: "instructor", country: "Finland", city: "Helsinki"}
+```
+
+#### Spread operator with arrow function
+
+Whenever we like to write an arrow function which takes unlimited number of arguments we use a spread operator. If we use a spread operator as a parameter, the argument passed when we invoke a function will change to an array.
+
+```js
+
+const sumAllNums = (...args) => {
+ console.log(args)
+}
+
+sumAllNums(1, 2, 3,4,5)
+
+```
+
+```sh
+[1, 2, 3, 4, 5]
+
+```
+
+```js
+
+const sumAllNums = (...args) => {
+ let sum = 0
+ for (const num of args){
+ sum += num
+ }
+ return sum
+
+}
+
+console.log(sumAllNums(1, 2, 3,4,5))
+```
+
+```sh
+15
+
+```
+
+π You achieved quite a lot so far. Now, your level of JavaScript is upper intermediate. Keep going! You have just completed day 11 challenges and you are 11 steps a head in to your way to greatness. Now do some exercises for your brain and for your muscle.
+
+## Exercises
+
+### Exercises: Level 1
+
+```js
+const constants = [2.72, 3.14, 9.81, 37, 100]
+const countries = ['Finland', 'Estonia', 'Sweden', 'Denmark', 'Norway']
+const rectangle = {
+ width: 20,
+ height: 10,
+ area: 200,
+ perimeter: 60
+}
+const users = [
+{
+ name:'Brook',
+ scores:75,
+ skills:['HTM', 'CSS', 'JS'],
+ age:16
+},
+{
+ name:'Alex',
+ scores:80,
+ skills:['HTM', 'CSS', 'JS'],
+ age:18
+},
+{
+ name:'David',
+ scores:75,
+ skills:['HTM', 'CSS'],
+ age:22
+},
+{
+ name:'John',
+ scores:85,
+ skills:['HTML'],
+ age:25
+},
+{
+ name:'Sara',
+ scores:95,
+ skills:['HTM', 'CSS', 'JS'],
+ age: 26
+},
+{
+ name:'Martha',
+ scores:80,
+ skills:['HTM', 'CSS', 'JS'],
+ age:18
+},
+{
+ name:'Thomas',
+ scores:90,
+ skills:['HTM', 'CSS', 'JS'],
+ age:20
+}
+]
+```
+
+1. Destructure and assign the elements of constants array to e, pi, gravity, humanBodyTemp, waterBoilingTemp.
+2. Destructure and assign the elements of countries array to fin, est, sw, den, nor
+3. Destructure the rectangle object by its properties or keys.
+
+### Exercises: Level 2
+
+1. Iterate through the users array and get all the keys of the object using destructuring
+2. Find the persons who have less than two skills
+
+
+### Exercises: Level 3
+
+1. Destructure the countries object print name, capital, population and languages of all countries
+2. A junior developer structure student name, skills and score in array of arrays which may not easy to read. Destruction the following array name to name, skills array to skills, scores array to scores, JavaScript score to jsScore and React score to reactScore variable.
+
+ ```js
+ const student = ['David', ['HTM', 'CSS', 'JS', 'React'], [98, 85, 90, 95]]
+ console.log(name, skills, scores, jsScore, reactScore)
+ ```
+
+3. Write a function called *convertArrayToObject* which can convert the array to a structure object.
+
+ ```js
+ const students = [
+ ['David', ['HTM', 'CSS', 'JS', 'React'], [98, 85, 90, 95]],
+ ['John', ['HTM', 'CSS', 'JS', 'React'], [85, 80, 85, 80]]
+ ]
+
+ console.log(convertArrayToObject(students))
+ [
+ {
+ name: 'David',
+ skills: ['HTM','CSS','JS','React'],
+ scores: [98,85,90,95]
+ },
+ {
+ name: 'John',
+ skills: ['HTM','CSS','JS','React'],
+ scores: [85, 80,85,80]
+ }
+ ]
+ ```
+
+4. Copy the student object to newStudent without mutating the original object. In the new object add the following ?
+
+- Add Bootstrap with level 8 to the front end skill sets
+- Add Express with level 9 to the back end skill sets
+- Add SQL with level 8 to the data base skill sets
+- Add SQL without level to the data science skill sets
+
+```js
+ const student = {
+ name: 'David',
+ age: 25,
+ skills: {
+ frontEnd: [
+ { skill: 'HTML', level: 10 },
+ { skill: 'CSS', level: 8 },
+ { skill: 'JS', level: 8 },
+ { skill: 'React', level: 9 }
+ ],
+ backEnd: [
+ { skill: 'Node',level: 7 },
+ { skill: 'GraphQL', level: 8 },
+ ],
+ dataBase:[
+ { skill: 'MongoDB', level: 7.5 },
+ ],
+ dataScience:['Python', 'R', 'D3.js']
+ }
+ }
+ ```
+
+ The copied object output should look like this:
+
+```js
+ {
+ name: 'David',
+ age: 25,
+ skills: {
+ frontEnd: [
+ {skill: 'HTML',level: 10},
+ {skill: 'CSS',level: 8},
+ {skill: 'JS',level: 8},
+ {skill: 'React',level: 9},
+ {skill: 'BootStrap',level: 8}
+ ],
+ backEnd: [
+ {skill: 'Node',level: 7},
+ {skill: 'GraphQL',level: 8},
+ {skill: 'Express',level: 9}
+ ],
+ dataBase: [
+ { skill: 'MongoDB',level: 7.5},
+ { skill: 'SQL',level: 8}
+ ],
+ dataScience: ['Python','R','D3.js','SQL']
+ }
+ }
+
+π CONGRATULATIONS ! π
+
+[<< Day 10](https://github.com/Asabeneh/30DaysOfJavaScript/blob/master/09_Day/09_day_Set_and_Map.md) | [Day 12>>](#)
\ No newline at end of file
diff --git a/readMe.md b/readMe.md
index f3dbaea..7993797 100644
--- a/readMe.md
+++ b/readMe.md
@@ -1,8 +1,5 @@
30 Days Of JavaScript
-
@@ -51,7 +48,7 @@
- [Checking Data types](#checking-data-types)
- [Comments](#comments)
- [Variables](#variables)
-- [π» Day 1: Exercises](#-day-1-exercises)
+- [π» Day 1: Exercises](#%f0%9f%92%bb-day-1-exercises)
# πDay 1
@@ -443,7 +440,7 @@ console.log(firstName); //not defined, because it is not assigned to a value yet
Null in JavaScript means an empty value.
```js
-let emptyValue = nulll
+let emptyValue = null
```
## Checking Data types
@@ -544,17 +541,30 @@ let firstName = 'Asabeneh' // first name of a person
let lastName = 'Yetayeh' // last name of a person
let country = 'Finland' // country
let city = 'Helsinki' // capital city
-let age = 100 // age in years
-let isMarried = true
+let isMarried = true // boolean data type
+
+console.log(firstName, lastName, country, city, age, isMarried)
+```
-console.log(firstName, lastName, country, city, age, isMarried); //Asabeneh, Yetayeh, Finland, Helsinki, 100, True
+```sh
+Asabeneh Yetayeh Finland Helsinki 100 True
+```
+```js
// Declaring variables with number values
+let age = 100 // age in years
const gravity = 9.81 // earth gravity in m/s2
const boilingPoint = 100 // water boiling point, temperature in oC
const PI = 3.14 // geometrical constant
-console.log(gravity, boilingPoint, PI); // 9.81, 100, 3.14
+console.log(gravity, boilingPoint, PI)
+```
+
+```sh
+9.81 100 3.14
+```
+
+```js
// Variables can also be declaring in one line separated by comma
let name = 'Asabeneh', // name of a person
job = 'teacher',
@@ -562,6 +572,10 @@ let name = 'Asabeneh', // name of a person
console.log(name, job, live);
```
+```sh
+Asabeneh teacher Finland
+```
+
When you run the files on 01-Day folder you should get this:
