Skip to content

Commit 73cb876

Browse files
authored
Update radix-sort.js
1 parent b92ccc3 commit 73cb876

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

radix-sort.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
const getNthDigit = (number, n) => {
2-
for (let i = 0; i < n; i++) {
3-
number = Math.floor(number / 10);
4-
}
2+
number >>= n;
53
return number % 10;
64
};
75

@@ -16,7 +14,7 @@ const extractElements = dictionary => {
1614
};
1715

1816
const radixSort = array => {
19-
let index = 0;
17+
let index = 1;
2018
while (true) {
2119
const dictionary = array.reduce((dict, element) => {
2220
const digit = getNthDigit(element, index);

0 commit comments

Comments
 (0)