Skip to content

Commit 8bb7084

Browse files
committed
Implement most method for radix sort
1 parent 6d3c096 commit 8bb7084

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

Sorting/RadixSort.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
function getDigit(num, position) {
2+
// get the digit in a specified position within an integer
23
num = String(num);
34
return position + 1 > num.length ? 0 : Number(num[num.length - 1 - position]);
45
}
56

67
function digitCount(num) {
8+
// get the number of digits in an integer
79
num = String(parseInt(num));
810
return num.length;
911
}
12+
13+
function mostDigits(nums) {
14+
// get the length of the number with the most digits in an array of numbers
15+
if (!nums.length) return 0;
16+
let max = Math.max(...nums);
17+
return digitCount(max);
18+
}

0 commit comments

Comments
 (0)