ts-sort-shell
Version:
shell sort an array in typescript
113 lines (70 loc) • 2.98 kB
Markdown
sync + callback + Promise + Async/Await style shellsort implementation in typescript
```js
npm install ts-sort-shell --save-dev
yarn add ts-sort-shell -D
```
```js
var shellSort = require("ts-sort-shell").shellSort;
shellSort([3,4,57,2,100,27,343],function(data){
console.log("shellSort cb",data.join('-'))// output: 2-3-4-27-57-100-343
})
var shellSortSync = require("ts-sort-shell").shellSortSync;
console.log('shellSortSync sync',shellSortSync([3,4,57,2,100,27,343]))// output: [2,3, 4, 27, 57,100,343]
var shellSortAsync = require("ts-sort-shell").shellSortAsync;
shellSortAsync([3,4,57,2,100,27,343]).then((res) => {
console.log('shellSortASync promise',res) // output: [2,3, 4, 27, 57,100,343]
}).catch((error) => {
console.log('err',error)
})
var shellSortAsyncW = require("ts-sort-shell").shellSortAsync;
(async function () {
var array4 = [3,4,57,2,100,27,343]
var les = await shellSortAsyncW(array4)
console.log('shellSortAsync await',les) // output: [2,3, 4, 27, 57,100,343]
})()
```
```js
import { shellSort, shellSortSync, shellSortAsync } from 'ts-sort-shell'
shellSort([3,4,57,2,100,27,343],function(data){
console.log("shellSort cb",data.join('-'))// output: 2-3-4-27-57-100-343
})
console.log('shellSortSync sync',shellSortSync([3,4,57,2,100,27,343]))
shellSortAsync([3,4,57,2,100,27,343]).then((res) => {
console.log('shellSortASync promise',res) // output: [2,3, 4, 27, 57,100,343]
}).catch((error) => {
console.log('err',error)
})
(async function () {
var array4 = [3,4,57,2,100,27,343]
var les = await shellSortAsync(array4)
console.log('shellSortAsyncAwait await',les) // output: [2,3, 4, 27, 57,100,343]
})()
```
```js
<script src="https://unpkg.com/ts-sort-shell@1.0.1/umd/index.js"></script>
tsSortShell.shellSort([3,4,57,2,100,27,343],function(data){
console.log("shellSort cb",data.join('-'))// output: 2-3-4-27-57-100-343
})
console.log('shellSortSync sync',tsSortShell.shellSortSync([3,4,57,2,100,27,343]))
tsSortShell.shellSortAsync([3,4,57,2,100,27,343]).then((res) => {
console.log('shellSortASync promise',res) // output: [2,3, 4, 27, 57,100,343]
}).catch((error) => {
console.log('err',error)
})
(async function () {
var array4 = [3,4,57,2,100,27,343]
var les = await tsSortShell.shellSortAsync(array4)
console.log('shellSortAsyncAwait await',les) // output: [2,3, 4, 27, 57,100,343]
})()
```
- arr - The array to sort in place
- callback - function to get sort array result