Skip to content

Commit

Permalink
feat: Menambahkan materi array manipulation (#157)
Browse files Browse the repository at this point in the history
* feat: Menambahkan materi array manipulation

* fix: fixing typo docs description

* fix: fixing typo docs description

* fix: rewrite the description of the function

Co-authored-by: grafisaholic <[email protected]>
  • Loading branch information
grafisaholic and grafisaholic authored Oct 21, 2021
1 parent 36d9762 commit 9c2d812
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions learn/basic/010_array_manipulation/sort.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,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 ]

0 comments on commit 9c2d812

Please sign in to comment.