Skip to content

Commit dc91021

Browse files
committed
array advanced
1 parent fc6791e commit dc91021

File tree

8 files changed

+94
-0
lines changed

8 files changed

+94
-0
lines changed

43. Array Sorting/index.html

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Document</title>
7+
</head>
8+
<body>
9+
10+
<script src="main.js"></script>
11+
</body>
12+
</html>

43. Array Sorting/main.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
let grades = [76,90,99,65,83,93,100,67]
2+
3+
let sortingdesce = grades.sort(descending).forEach(print)
4+
5+
let sortingasce = grades.sort(ascending).forEach(print)
6+
7+
function descending(a,b){
8+
return b - a
9+
}
10+
11+
function ascending(a,b){
12+
return a - b
13+
}
14+
15+
function print(x){
16+
console.log(x)
17+
}
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Document</title>
7+
</head>
8+
<body>
9+
<label id="mylabel">0</label><br>
10+
<button id="increasebutton" onclick="increasebutton()">increase</button>
11+
<button id="decreasebutton" onclick="decreasebutton()">decrease</button>
12+
<button id="resetbutton" onclick="resetbutton()">Reset</button>
13+
14+
<script src="main.js"></script>
15+
</body>
16+
</html>
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// on expressions = function without a name (anonymous function)
2+
// avoid poluting the global scope with names
3+
// Write it, the forget about
4+
5+
let count = 0
6+
7+
function increasebutton(){
8+
count += 1
9+
document.getElementById("mylabel").innerHTML = count
10+
}
11+
12+
function decreasebutton(){
13+
count -= 1
14+
document.getElementById("mylabel").innerHTML = count
15+
}
16+
17+
function resetbutton(){
18+
count = 0
19+
document.getElementById("mylabel").innerHTML = count
20+
}

45. Arrow Function/index.html

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Document</title>
7+
</head>
8+
<body>
9+
10+
<script src="main.js"></script>
11+
</body>
12+
</html>

45. Arrow Function/main.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
let array = [13,15,11,1,9,10,20,4]
2+
3+
array
4+
.sort((a, b) => a - b)
5+
.forEach ((x) => console.log(x))

46. Shuffle An array/index.html

Whitespace-only changes.

46. Shuffle An array/main.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
let cards = ["A", "2", "3", "4","5","6","7","8","9","10","J","Q","K"]
2+
3+
shuffle(cards)
4+
5+
function shuffle (array){
6+
let currenindex = array.length
7+
8+
while(currenindex != 0){
9+
let randomindex = Math.floor(Math.random() * currenindex)
10+
currenindex -= 1
11+
}
12+
}

0 commit comments

Comments
 (0)