Travis build: 425

This commit is contained in:
Travis CI
2017-12-28 11:44:44 +00:00
parent 3c93f0519b
commit db684cdd44
4 changed files with 63 additions and 5 deletions

View File

@ -249,6 +249,15 @@
</details>
### _Uncategorized_
<details>
<summary>View contents</summary>
* [`quickSort`](#quicksort)
</details>
## Adapter
### call
@ -4002,6 +4011,33 @@ validateNumber('10'); // true
[⬆ Back to top](#table-of-contents)
## _Uncategorized_
### quickSort
QuickSort an Array (ascending sort by default).
Use recursion.
Use `Array.filter` and spread operator (`...`) to create an array that all elements with values less than the pivot come before the pivot, and all elements with values greater than the pivot come after it.
If the parameter `desc` is truthy, return array sorts in descending order.
```js
const quickSort = ([n, ...nums], desc) =>
isNaN(n)
? []
: [
...quickSort(nums.filter(v => (desc ? v > n : v <= n)), desc),
n,
...quickSort(nums.filter(v => (!desc ? v > n : v <= n)), desc)
];
```
```js
quickSort([4, 1, 3, 2]); // [1,2,3,4]
quickSort([4, 1, 3, 2], true); // [4,3,2,1]
```
[⬆ back to top](#table-of-contents)
## Credits