forked from bellshade/Javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsort.js
More file actions
24 lines (19 loc) · 704 Bytes
/
Copy pathsort.js
File metadata and controls
24 lines (19 loc) · 704 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// 1. Membuat contoh variable array
const arrayPoint = [40, 100, 1, 5, 25, 10];
// 2. Membuat fungsi untuk mengurutkan angka dalam array dari yang terkecil hingga terbesar.
function sortAscending(point) {
let result = point.sort(function (a, b) {
return a - b;
});
return result;
}
// 3. Membuat fungsi untuk mengurutkan angka dalam array dari yang terbesar hingga terkecil.
function sortDescending(point) {
let result = point.sort(function (a, b) {
return b - a;
});
return result;
}
// 4. Penerapan menggunakan contoh variable arrayPoint
console.log(sortAscending(arrayPoint)); // [ 1, 5, 10, 25, 40, 100 ]
console.log(sortDescending(arrayPoint)); // [ 100, 40, 25, 10, 5, 1 ]