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 3 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
27 changes: 27 additions & 0 deletions learn/basic/010_array_manipulation/sort.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
function sortAscending(point) {
let result = point.sort(function (a, b) {
return a - b;
});

return result;
}

function sortDescending(point) {
let result = point.sort(function (a, b) {
return b - a;
});

return result;
}

const arrayPoint = [40, 100, 1, 5, 25, 10];

console.log(sortAscending(arrayPoint)); // [ 1, 5, 10, 25, 40, 100 ]
console.log(sortDescending(arrayPoint)); // [ 100, 40, 25, 10, 5, 1 ]

/**
* PENJELASAN :
* SORT dalam bahasa indonesia berarti mengurutkan
* sortAscending bertujuan untuk mengurutkan angka dalam array dari yang terkecil hingga terbesar.
* sortDescending bertujuan untuk mengurutkan angka dalam array dari yang terbesar hingga terkecil.
*/