GeezerVison is showing github.com — Add of exercises and some courses · youxiberlin/javascript@b47cf7b
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: SUMMARY.md +3-7Lines changed: 3 additions & 7 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
|
21 | 21 | * [Arrays](arrays/README.md) |
22 | 22 | * [Indices](arrays/indices.md) |
23 | 23 | * [Length](arrays/length.md) |
| 24 | + * [Array Methods](arrays/array_methods.md) |
24 | 25 | * [Loops](loops/README.md) |
25 | 26 | * [For](loops/for.md) |
26 | 27 | * [While](loops/while.md) |
27 | 28 | * [Do...While](loops/dowhile.md) |
28 | 29 | * [Functions](functions/README.md) |
29 | 30 | * [Declare](functions/declare.md) |
30 | | - * [Higher order](functions/higher_order.md) |
| 31 | + * [Higher order (Advanced)](functions/higher_order.md) |
31 | 32 | * [Objects](objects/README.md) |
32 | 33 | * [Creation](objects/creation.md) |
33 | 34 | * [Properties](objects/properties.md) |
34 | | - * [Mutable](objects/mutable.md) |
35 | | - * [Reference](objects/reference.md) |
36 | | - * [Prototype](objects/prototype.md) |
37 | | - * [Delete](objects/delete.md) |
38 | | - * [Enumeration](objects/enumeration.md) |
39 | | - * [Global footprint](objects/global_footprint.md) |
| 35 | + * [Reference (Advanced)](objects/reference.md) |
40 | 36 | * [Exercises](exercises/README.md) |
41 | 37 | * [All Exercises](exercises/all_exercises.md) |
42 | 38 |
|
Collapse file
Copy file name to clipboard +32Lines changed: 32 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +# Push |
| 2 | + |
| 3 | +You can insert elements inside an array with their method `push`. In fact, there is many other properties: |
| 4 | +- `push(n)`: Add the element `n` at the end |
| 5 | +- `pop()`: Remove the last element |
| 6 | +- `sort()`: Sort the array by lexicographical order |
| 7 | + |
| 8 | +```javascript |
| 9 | +var array = [1, 2, 4]; |
| 10 | +array.push(8); |
| 11 | +// Now array = [1, 2, 4, 8] |
| 12 | +``` |
| 13 | + |
| 14 | +{% exercise %} |
| 15 | +Add the city "Paris" to cities and sort it |
| 16 | +{% initial %} |
| 17 | +var cities = ["Madrid", "Barcelona", "Miami"]; |
| 18 | + |
| 19 | + |
| 20 | +var a = |
| 21 | +{% solution %} |
| 22 | +var cities = ["Madrid", "Barcelona", "Miami"]; |
| 23 | +cities.push("Paris"); |
| 24 | +cities.sort(); |
| 25 | + |
| 26 | +{% validation %} |
| 27 | +assert (cities.length === 4); |
| 28 | +assert (cities[0] === "Barcelona"); |
| 29 | +assert (cities[1] === "Madrid"); |
| 30 | +assert (cities[2] === "Miami"); |
| 31 | +assert (cities[3] === "Paris"); |
| 32 | +{% endexercise %} |