forked from nas5w/javascript-patterns
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathradixSort.js
More file actions
31 lines (30 loc) · 679 Bytes
/
radixSort.js
File metadata and controls
31 lines (30 loc) · 679 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
25
26
27
28
29
30
31
function radixSort(arr) {
let temp;
let stop = false;
let arrc = [];
for(let i in arr)
arrc[i] = arr[i];
while(!stop) {
for (let i = 0; i < arrc.length; i++){
for (let j = 1; j < arrc.length; j++) {
if ((arrc[j] % 10) < (arrc[j - 1] % 10)) {
temp = arrc[j];
arrc[j] = arrc[j - 1];
arrc[j - 1] = temp;
temp = arr[j];
arr[j] = arr[j - 1];
arr[j - 1] = temp;
}
}
}
stop = true;
for (let z = 0; z < arrc.length; z++)
{
arrc[z] /= 10;
if (arrc[z] != 0)
stop = false;
}
}
return arr;
}
module.exports = radixSort;