File tree Expand file tree Collapse file tree 2 files changed +10
-3
lines changed
Expand file tree Collapse file tree 2 files changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -128,14 +128,18 @@ export const compareStrings = (a: string, b: string) => {
128128 // }
129129} ;
130130
131- export const sortProducts = ( products : ProductTuple [ ] , method : SortMethod ) => {
131+ // Using Bubble Sort
132+ export const sortProducts = ( products : ProductTuple [ ] , method : SortMethod = "ascending" ) => {
132133 const result = filterProductsById ( products ) ;
133134
134135 for ( let p = 0 ; p < products . length ; p ++ ) {
136+ // Outer pass
135137 // iterate over products
136138
137139 for ( let i = 0 ; i < result . length ; i ++ ) {
140+ // Inner pass
138141 // sort each product by pick location
142+
139143 const currentProduct = result [ i ] ;
140144 const nextProduct = result [ i + 1 ] ;
141145
Original file line number Diff line number Diff line change @@ -39,10 +39,13 @@ async function run(args: string[], options: CliOptions = {}) {
3939 checkColumns ( columns ) ;
4040 logger . info ( `processing ${ rows . length } rows` ) ;
4141
42- const sortedRows = sortProducts ( rows , "ascending" ) ;
42+ const startedSort = Date . now ( ) ;
43+ const sortedRows = sortProducts ( rows ) ;
44+ const finishedSort = Date . now ( ) ;
4345
4446 const sortedProducts = [ columns , ...sortedRows ] ;
45- logger . success ( `sorted ${ sortedProducts . length - 1 } products` ) ;
47+ const timeToSort = finishedSort - startedSort ;
48+ logger . success ( `sorted ${ sortedRows . length } products in ${ timeToSort } ms` ) ;
4649
4750 createCsvFile ( options . output , sortedProducts ) ;
4851}
You can’t perform that action at this time.
0 commit comments