for example, an array:
[235, 42, 8, 100]
now you need to sort by last bit , and the final result should be:
[100, 42, 235, 8]
excuse me: how to achieve this function, what is needed is an algorithm
< hr >Thank you for @ lejoy"s advice. A simple bubble last sort can be as follows:
function sort(arr) {
for (let i = 0; i < arr.length; iPP) {
for (let j = 1; j < arr.length; jPP) {
// ...
if (arr[j] % 10 < arr[j - 1] % 10) {
let tmp = arr[j - 1]
arr[j - 1] = arr[j]
arr[j] = tmp
}
}
}
console.log(arr)
}
sort([55, 41, 32, 23, 19])