File tree Expand file tree Collapse file tree 2 files changed +8
-10
lines changed
Expand file tree Collapse file tree 2 files changed +8
-10
lines changed Original file line number Diff line number Diff line change 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 ;
Original file line number Diff line number Diff line change 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
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 = [ ] ,
8586 var less = getLessCount ( getCount ( array ) ) ;
8687 return sort ( array , less ) ;
8788 } ;
88- } ( ) ;
89+ } ( ) ) ;
8990
9091 exports . countingSort = countingSort ;
9192
You can’t perform that action at this time.
0 commit comments