Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Menambahkan materi array manipulation #157

Merged
merged 4 commits into from
Oct 21, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 ]