You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 05_Day/05_day_arrays.md
+38-38Lines changed: 38 additions & 38 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,7 +17,7 @@
17
17
18
18

19
19
20
-
-[📔 Day 5](#%f0%9f%93%94-day-5)
20
+
-[📔 Day 5](#-day-5)
21
21
-[Arrays](#arrays)
22
22
-[How to create an empty array](#how-to-create-an-empty-array)
23
23
-[How to create an array with values](#how-to-create-an-array-with-values)
@@ -43,7 +43,7 @@
43
43
-[Reversing array order](#reversing-array-order)
44
44
-[Sorting elements in array](#sorting-elements-in-array)
45
45
-[Array of arrays](#array-of-arrays)
46
-
-[💻 Exercise](#%f0%9f%92%bb-exercise)
46
+
-[💻 Exercise](#-exercise)
47
47
-[Exercise: Level 1](#exercise-level-1)
48
48
-[Exercise: Level 2](#exercise-level-2)
49
49
-[Exercise: Level 3](#exercise-level-3)
@@ -52,14 +52,14 @@
52
52
53
53
## Arrays
54
54
55
-
In contrast to variables, an array can store _multiple values_. Each value in an array has an _index_, and each index has _a reference in a memory address_. Each value can be accessed by using their _indexes_. The index of an array starts from _zero_, and the last element is less by one from the length of the array.
55
+
In contrast to variables, an array can store _multiple values_. Each value in an array has an _index_, and each index has _a reference in a memory address_. Each value can be accessed by using their _indexes_. The index of an array starts from _zero_, and the index of the last element is less by one from the length of the array.
56
56
57
57
An array is a collection of different data types which are ordered and changeable(modifiable). An array allows storing duplicate elements and different data types. An array can be empty, or it may have different data type values.
58
58
59
59
### How to create an empty array
60
60
61
-
In JavaScript, we can create an array in different ways. Let us different ways to create an array.
62
-
It is very common to use *const* instead of *let* to declare an array variable. If you ar using const it means you do not use that name again.
61
+
In JavaScript, we can create an array in different ways. Let us see different ways to create an array.
62
+
It is very common to use *const* instead of *let* to declare an array variable. If you ar using const it means you do not use that variable name again.
63
63
64
64
- Using Array constructor
65
65
@@ -166,7 +166,7 @@ console.log(words)
166
166
167
167
### Accessing array items using index
168
168
169
-
We access each element in an array using their index. An array index starts from 0. The picture below clearly shows the starting of the index.
169
+
We access each element in an array using their index. An array index starts from 0. The picture below clearly shows the index of each element in the array.
join: It used to join the elements of the array, the argument passed in the join method will be joined in the array and return as a string. By default, it joins with a comma, but we can pass different string parameter which can be joined between the items.
477
+
join: It is used to join the elements of the array, the argument we passed in the join method will be joined in the array and return as a string. By default, it joins with a comma, but we can pass different string parameter which can be joined between the items.
478
478
479
479
```js
480
480
constnumbers= [1, 2, 3, 4, 5]
@@ -532,8 +532,8 @@ Splice: It takes three parameters:Starting position, number of times to be remov
532
532
```
533
533
534
534
```js
535
-
constnumbers= [1, 2, 3, 4, 5];
536
-
console.log(numbers.splice(3, 3, 6, 7, 8)) // -> [1, 2, 3, 6, 7, 8] //it removes two item and replace three items
535
+
constnumbers= [1, 2, 3, 4, 5, 6];
536
+
console.log(numbers.splice(3, 3, 7, 8, 9)) // -> [1, 2, 3, 7, 8, 9] //it removes three item and replace three items
sort: arrange array elements in ascending order. Sort takes a call back function, we will see how we use sort with call back function in the coming sections.
621
+
sort: arrange array elements in ascending order. Sort takes a call back function, we will see how we use sort with a call back function in the coming sections.
622
622
623
623
```js
624
624
constwebTechs= [
@@ -691,33 +691,33 @@ const webTechs = [
691
691
```
692
692
693
693
1. Declare an _empty_ array;
694
-
1. Declare an array with more than 5 number of elements
695
-
1. Find the length of your array
696
-
1. Get the first item, the middle item and the last item of the array
697
-
1. Declare an array called _mixedDataTypes_,put different data types in your array and find length of the array. You are should size be greater than 5
698
-
1. Declare an array variable name itCompanies and assign initial values Facebook, Google, Microsoft, Apple, IBM, Oracle and Amazon
699
-
1. Print the array using _console.log()_
700
-
1. Print the number of companies in the array
701
-
1. Print the first company, middle and last company
702
-
1. Print out each company
703
-
1. Change each company name to uppercase one by one and print them out
704
-
1. Print the array like as a sentence: Facebook, Google, Microsoft, Apple, IBM,Oracle and Amazon are big IT companies.
705
-
1. Check if a certain company exists in the itCompanies array. If it exist return the company else return a company is _not found_
706
-
1. Filter out companies which have more than one 'o' without the filter method
707
-
1. Sort the array using _sort()_ method
708
-
1. Reverse the array using _reverse()_ method
709
-
1. Slice out the first 3 companies from the array
710
-
1. Slice out the last 3 companies from the array
711
-
1. Slice out the middle IT company or companies from the array
712
-
1. Remove the first IT company from the array
713
-
1. Remove the middle IT company or companies from the array
714
-
1. Remove the last IT company from the array
715
-
1. Remove all IT companies
694
+
2. Declare an array with more than 5 number of elements
695
+
3. Find the length of your array
696
+
4. Get the first item, the middle item and the last item of the array
697
+
5. Declare an array called _mixedDataTypes_,put different data types in the array and find the length of the array. The array size should be greater than 5
698
+
6. Declare an array variable name itCompanies and assign initial values Facebook, Google, Microsoft, Apple, IBM, Oracle and Amazon
699
+
7. Print the array using _console.log()_
700
+
8. Print the number of companies in the array
701
+
9. Print the first company, middle and last company
702
+
10. Print out each company
703
+
11. Change each company name to uppercase one by one and print them out
704
+
12. Print the array like as a sentence: Facebook, Google, Microsoft, Apple, IBM,Oracle and Amazon are big IT companies.
705
+
13. Check if a certain company exists in the itCompanies array. If it exist return the company else return a company is _not found_
706
+
14. Filter out companies which have more than one 'o' without the filter method
707
+
15. Sort the array using _sort()_ method
708
+
16. Reverse the array using _reverse()_ method
709
+
17. Slice out the first 3 companies from the array
710
+
18. Slice out the last 3 companies from the array
711
+
19. Slice out the middle IT company or companies from the array
712
+
20. Remove the first IT company from the array
713
+
21. Remove the middle IT company or companies from the array
714
+
22. Remove the last IT company from the array
715
+
23. Remove all IT companies
716
716
717
717
### Exercise: Level 2
718
718
719
-
1. Create a separate countries.js file and store the countries array in to this file, create a separate file web_techs.js ans store the webTechs array in to this file. Access both file in main.js file
720
-
1. First remove all the functions and change the string to array and count the number of words in the array
719
+
1. Create a separate countries.js file and store the countries array in to this file, create a separate file web_techs.js and store the webTechs array in to this file. Access both file in main.js file
720
+
1. First remove all the punctuations and change the string to array and count the number of words in the array
- add 'Meat'in the beginning of your shopping cart ififit has not be already added
742
-
- add sugar at the end of you shopping cart if it has not been already added
743
-
-Remove'Honey'if you are allergic to honey
744
-
- modify tea to 'Green Tea'
741
+
- add 'Meat'in the beginning of your shopping cart if it has not been already added
742
+
- add Sugar at the end of you shopping cart if it has not been already added
743
+
-remove'Honey'if you are allergic to honey
744
+
- modify Tea to 'Green Tea'
745
745
1. In countries array check if'Ethiopia' exists in the array if it exists print 'ETHIOPIA'. If it does not exist add to the countries list.
746
746
1. In the webTechs array check if Sass exists in the array and if it exists print 'Sass is a CSS preprocess'. If it does not exist add Sass to the array and print the array.
747
747
1. Concatenate the following two variables and store it in a fullStack variable.
0 commit comments