Use timer
⏰
Use math
👩🏻💻
let januaryTemperature = -15.4;
let februaryTemperature = -17.2;
let marchTemperature = 2.7;
let aprilTemperature = 12.6;
let mayTemperature = 23.0;
let juneTemperature = 27.1;
let julyTemperature = 28.8;
let augustTemperature = 25.4;
let septemberTemperature = 18.9;
let octoberTemperature = 15.2;
let novemberTemperature = -1.7;
let decemberTemperature = -9.6;
Monthly average temperature for one year
For several years?
Calculate average per year?
Check tendency for 10 years?
let monthlyTemperature = [
-15.4, -17.2, 2.7, 12.6,
23.0, 27.1, 28.8, 25.4,
18.9, 15.2, -1.7, -9.6
];
Monthly average temperature for one year
For several years!
Calculate average per year!
Check tendency for 10 years!
let averagePerYear = monthlyTemperature.reduce(
(acc, item) => acc + item,
0
) / monthlyTemperature.length;
[0]
[1]
[2]
[3]
[...]
-15.4
-17.2
2.7
12.6
...
[0]
[1]
[2]
[3]
-15.4
-17.2
2.7
12.6
[4]
23.0
let monthlyTemperature = [ -15.4, -17.2, 2.7 ];
monthlyTemperature.push( 12.6 );
🐱
🐶
🐭
NULL
Node
HEAD
🐱
🐶
🐭
NULL
Node
HEAD
🦄
New node
HEAD
🐱
🐶
🐭
NULL
Node
HEAD
🦄
New node
🐱
🐶
🐭
NULL
HEAD
🦄
🐱
🐶
🐭
NULL
HEAD
🦄
🐱
🐶
🐭
NULL
Node
HEAD
NULL
TAIL
🐱
🐶
🐭
NULL
Node
HEAD
NULL
TAIL
🦄
New node
🐱
🐶
🐭
NULL
Node
HEAD
NULL
TAIL
🦄
New node
🐱
🐶
🐭
NULL
Node
HEAD
NULL
TAIL
🐱
🐶
🐭
NULL
Node
HEAD
NULL
TAIL
🐱
🐶
🐭
HEAD
🐱
🐶
🐭
HEAD
TAIL
1
2
3
Push
Pop
4
Top
5
2
3
Push 5
4
Empty stack
Push 2
5
2
Push 4
4
5
2
Push 3
5
2
3
4
5
2
4
5
2
Pop
Pop
1
2
3
Enqueue
Dequeue
4
Front
1
End
Front
1
2
3
4
1
2
3
End
Front
Enqueue 2
Enqueue 3
Enqueue 4
Front
End
4
End
Front
1
2
3
4
3
End
Front
Dequeue
Dequeue
Dequeue
Front
End
4
Mike
Paul
Sara
John
Paul
N = { 1, 2, 3, 4, ... , 100, ... }
A = { x, y, z }
Data structure with unique elements
IconMap = {
< 'Avocado': '🥑' >
< 'Pizza': '🍕' >
}
Data structure with pairs <key, value>, where keys are unique
Linear Probing
Separate Chaining
Use next position
Use list of values
Root - 1
Leaf - 6, 7, 8, 3, 12, 10, 11
Height - 3
1. Find item by value
2. Check type of selected item:
2.1. Leaf - it's cool (do nothing)
2.2. Has only one child: left or right (set this child node instead of current node)
2.3. Has both children (find min from the right child and set this value on current position, deleting min node)
10
8
12
15
21
23
Balanced Tree
Min Heap
1. Create a new node with item at the end of heap.
2. Compare the value of new node with its parent.
3. If value of parent is greater than child, then swap them.
4. Go to step 2.
1. Remove root node.
2. Move the last element of last level to root.
3. Go to step 2 & 3 from "Add Item" section.
0
1
2
10
3
4
5
6
7
8
9
10
14
19
26
31
42
27
44
35
33
Index
Left child: 2*n
Right child: 2*n+1
Parent: Math.floor(n/2)