@any86/quick-sort
Advanced tools
| declare type Compare<T> = (pivotItem: T, currentItem: T) => number; | ||
| export default function quickSort<Item = number>(array: Item[], compareFn?: Compare<Item>): Item[]; | ||
| export {}; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| function compareNumber(pivotItem, currentItem) { | ||
| return pivotItem - currentItem; | ||
| } | ||
| function partition(array, startIndex, endIndex, compareFn) { | ||
| const pivot = array[startIndex]; | ||
| let divideIndex = startIndex; | ||
| for (let i = startIndex + 1; i <= endIndex; i++) { | ||
| if (0 > compareFn(array[i], pivot)) { | ||
| divideIndex++; | ||
| swap(array, divideIndex, i); | ||
| } | ||
| } | ||
| swap(array, divideIndex, startIndex); | ||
| return divideIndex; | ||
| } | ||
| function swap(array, i, j) { | ||
| const v = array[i]; | ||
| array[i] = array[j]; | ||
| array[j] = v; | ||
| } | ||
| function quickSort(array, compareFn = compareNumber) { | ||
| const startIndex = 0; | ||
| const endIndex = array.length - 1; | ||
| const stack = []; | ||
| stack.push([startIndex, endIndex]); | ||
| while (0 !== stack.length) { | ||
| const [startIndex, endIndex] = stack.pop(); | ||
| const pivotIndex = partition(array, startIndex, endIndex, compareFn); | ||
| if (startIndex < pivotIndex - 1) { | ||
| stack.push([startIndex, pivotIndex - 1]); | ||
| } | ||
| if (pivotIndex + 1 < endIndex) { | ||
| stack.push([pivotIndex + 1, endIndex]); | ||
| } | ||
| } | ||
| return array; | ||
| } | ||
| exports.default = quickSort; | ||
| //# sourceMappingURL=index.js.map |
| {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAOA,SAAS,aAAa,CAAC,SAAiB,EAAE,WAAmB;IACzD,OAAO,SAAS,GAAG,WAAW,CAAC;AACnC,CAAC;AASD,SAAS,SAAS,CAAgB,KAAa,EAAE,UAAkB,EAAE,QAAgB,EAAE,SAAwB;IAE3G,MAAM,KAAK,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC;IAEhC,IAAI,WAAW,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,CAAC,CAAC;SAC5C;QACD,IAAI,UAAU,GAAG,CAAC,GAAG,QAAQ,EAAE;YAC3B,KAAK,CAAC,IAAI,CAAC,CAAC,UAAU,GAAG,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC;SAC1C;KACJ;IACD,OAAO,KAAK,CAAC;AACjB,CAAC;AAjBD,4BAiBC"} |
| "use strict";Object.defineProperty(exports,"__esModule",{value:true});function compareNumber(pivotItem,currentItem){return pivotItem-currentItem}function partition(array,startIndex,endIndex,compareFn){const pivot=array[startIndex];let divideIndex=startIndex;for(let i=startIndex+1;i<=endIndex;i++){if(0>compareFn(array[i],pivot)){divideIndex++;swap(array,divideIndex,i)}}swap(array,divideIndex,startIndex);return divideIndex}function swap(array,i,j){const v=array[i];array[i]=array[j];array[j]=v}function quickSort(array,compareFn=compareNumber){const startIndex=0;const endIndex=array.length-1;const stack=[];stack.push([startIndex,endIndex]);while(0!==stack.length){const[startIndex,endIndex]=stack.pop();const pivotIndex=partition(array,startIndex,endIndex,compareFn);if(startIndex<pivotIndex-1){stack.push([startIndex,pivotIndex-1])}if(pivotIndex+1<endIndex){stack.push([pivotIndex+1,endIndex])}}return array}exports.default=quickSort; |
+21
| MIT License | ||
| Copyright (c) 2020 Russell | ||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| of this software and associated documentation files (the "Software"), to deal | ||
| in the Software without restriction, including without limitation the rights | ||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| copies of the Software, and to permit persons to whom the Software is | ||
| furnished to do so, subject to the following conditions: | ||
| The above copyright notice and this permission notice shall be included in all | ||
| copies or substantial portions of the Software. | ||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| SOFTWARE. |
+3
-2
| { | ||
| "name": "@any86/quick-sort", | ||
| "version": "0.0.5", | ||
| "version": "0.0.6", | ||
| "description": "快速排序", | ||
@@ -44,3 +44,4 @@ "main": "dist/index.js", | ||
| "typescript": "^4.6.0" | ||
| } | ||
| }, | ||
| "gitHead": "3aac237dd4134f596318488309bfacd2aea12aac" | ||
| } |
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
Mixed license
LicensePackage contains multiple licenses.
Found 1 instance in 1 package
Empty package
Supply chain riskPackage does not contain any code. It may be removed, is name squatting, or the result of a faulty package publish.
Found 1 instance in 1 package
6684
313.61%7
250%43
Infinity%0
-100%1
Infinity%3
50%