Skip to content

Commit 1a14fd0

Browse files
committed
Change the count of the buckets
1 parent 32a7b4c commit 1a14fd0

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

src/sorting/linearsort/bucketsort.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,12 @@
4343
*/
4444
function createBuckets(array) {
4545
var buckets = [],
46-
currentBucket,
47-
current,
48-
sectorSize = 1 / array.length;
46+
length = array.length,
47+
currentBucket, current;
4948
for (var i = 0; i < array.length; i += 1) {
5049
current = array[i];
51-
currentBucket = Math.floor(current / sectorSize);
52-
if (buckets[currentBucket] === undefined) {
53-
buckets[currentBucket] = [];
54-
}
50+
currentBucket = Math.floor(length % current);
51+
buckets[currentBucket] = buckets[currentBucket] || [];
5552
buckets[currentBucket].push(current);
5653
}
5754
return buckets;

src/sorting/linearsort/countingsort.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
* @public
1010
*/
11-
var countingSort = function () {
11+
var countingSort = (function () {
1212

1313
/**
1414
* Gets the count of the elements into the input array
@@ -36,7 +36,8 @@
3636
*
3737
* @private
3838
* @param {array} array The input array
39-
* @returns {array} less The count of the elements which are less than each element from the input
39+
* @returns {array} less The count of the elements which
40+
* are less than each element from the input
4041
*/
4142
function getLessCount(array) {
4243
var less = [],
@@ -85,7 +86,7 @@
8586
var less = getLessCount(getCount(array));
8687
return sort(array, less);
8788
};
88-
}();
89+
}());
8990

9091
exports.countingSort = countingSort;
9192

0 commit comments

Comments
 (0)