@any86/quick-sort
Advanced tools
+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. |
+1
-1
| declare type Compare<T> = (pivotItem: T, currentItem: T) => number; | ||
| export declare function quickSort<Item = number>(array: Item[], compareFn?: Compare<Item>): Item[]; | ||
| export default function quickSort<Item = number>(array: Item[], compareFn?: Compare<Item>): Item[]; | ||
| export {}; |
+1
-1
@@ -21,3 +21,3 @@ function compareNumber(pivotItem, currentItem) { | ||
| } | ||
| export function quickSort(array, compareFn = compareNumber) { | ||
| export default function quickSort(array, compareFn = compareNumber) { | ||
| const startIndex = 0; | ||
@@ -24,0 +24,0 @@ const endIndex = array.length - 1; |
@@ -1,1 +0,1 @@ | ||
| {"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,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C,CAAC,CAAC,GAAG,CAAC,CAAC;AACjB,CAAC;AAWD,MAAM,CAAC,OAAO,UAAU,SAAS,CAAgB,KAAa,EAAE,YAA2B,aAAoB;IAC3G,MAAM,UAAU,GAAG,CAAC,CAAC;IACrB,MAAM,QAAQ,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;IAElC,MAAM,KAAK,GAAuB,EAAE,CAAC;IACrC,KAAK,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC,CAAC;IACnC,OAAO,CAAC,KAAK,KAAK,CAAC,MAAM,EAAE;QACvB,MAAM,CAAC,UAAU,EAAE,QAAQ,CAAC,GAAG,KAAK,CAAC,GAAG,EAAG,CAAC;QAC5C,MAAM,UAAU,GAAG,SAAS,CAAC,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;QACrE,IAAI,UAAU,GAAG,UAAU,GAAG,CAAC,EAAE;YAC7B,KAAK,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,UAAU,GAAG,CAAC,CAAC,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"} |
@@ -1,1 +0,1 @@ | ||
| 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}export 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} | ||
| 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}export default 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} |
+2
-2
| { | ||
| "name": "@any86/quick-sort", | ||
| "version": "0.0.1", | ||
| "version": "0.0.2", | ||
| "description": "点击指定元素之外触发", | ||
@@ -42,3 +42,3 @@ "main": "dist/index.js", | ||
| }, | ||
| "gitHead": "2c649acc381f6ebdd04fbf2a8220f92dc5108a20" | ||
| "gitHead": "34b69a4b006a33c602e955783bcae4563ae1e2b3" | ||
| } |
+13
-46
@@ -1,16 +0,12 @@ | ||
| # be-full | ||
| # @any86/quick-sort | ||
| [![NPM Version][npm-image]][npm-url] | ||
| [npm-image]: https://badgen.net/npm/v/@6h/be-full | ||
| [npm-url]: https://npmjs.org/package/@6h/be-full | ||
| [npm-image]: https://badgen.net/npm/v/@any86/quick-sort | ||
| [npm-url]: https://npmjs.org/package/@any86/quick-sort | ||
| 🍔 任意元素**全屏**显示, 支持PC/移动端, 不到**1kb**. | ||
| 快速排序, 原地排序, 非递归版本. | ||
| ## 在线演示 | ||
| [:rocket: 演示](https://any86.github.io/be-full/example/) | ||
| ## 安装 | ||
| ```shell | ||
| npm i -S be-full | ||
| npm i -S @any86/quick-sort | ||
| ``` | ||
@@ -21,40 +17,11 @@ | ||
| ```javascript | ||
| import {beFull} from 'be-full'; | ||
| import qSort from '@any86/quick-sort'; | ||
| // 整个网页全屏显示 | ||
| beFull(); | ||
| // 正序排列 | ||
| const array1 = [100,1,99]; | ||
| const arraySorted = qSort(array); | ||
| // 指定元素全屏 | ||
| beFull(document.getElementById('video')); | ||
| ``` | ||
| ## 🔥更多API(4个函数) | ||
| ### exitFull(退出全屏) | ||
| ```javascript | ||
| exitFull(); | ||
| ``` | ||
| ### toggleFull(切换全屏/退出) | ||
| 使用方法同`beFull`, 只是第二次点击会执行`exitFull` | ||
| ```javascript | ||
| toggleFull(); | ||
| // 切换指定元素全屏/退出 | ||
| toggleFull(document.getElementById('video')); | ||
| ``` | ||
| ### isFull(元素是否全屏) | ||
| ```javascript | ||
| isFull(document.getElementById('video')); | ||
| ``` | ||
| ### watchFull(监视元素全屏状态变化) | ||
| ```javascript | ||
| const {cancel} = watchFull(document.documentElement, ev => { | ||
| // 全屏状态变化执行 | ||
| }); | ||
| // 取消监听 | ||
| cancel(); | ||
| ``` | ||
| // 倒序排列, 指定排序的字段 | ||
| const array1 = [{a:100},{a:1},{a:99}]; | ||
| const array1Sorted = qSort(array1, (a,b)=>b.a-a.a); | ||
| ``` |
+1
-1
@@ -50,3 +50,3 @@ type Compare<T> = (pivotItem: T, currentItem: T) => number; | ||
| */ | ||
| export function quickSort<Item = number>(array: Item[], compareFn: Compare<Item> = compareNumber as any): Item[] { | ||
| export default function quickSort<Item = number>(array: Item[], compareFn: Compare<Item> = compareNumber as any): Item[] { | ||
| const startIndex = 0; | ||
@@ -53,0 +53,0 @@ const endIndex = array.length - 1; |
Mixed license
LicensePackage contains multiple licenses.
Found 1 instance in 1 package
8798
6.4%10
11.11%1
Infinity%26
-56.67%