mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-07 02:05:08 +08:00
Cocktail Shaker Sort | Added Doctests
This commit is contained in:
@ -8,6 +8,18 @@
|
|||||||
* Wikipedia (Bubble Sort): https://en.wikipedia.org/wiki/Bubble_sort
|
* Wikipedia (Bubble Sort): https://en.wikipedia.org/wiki/Bubble_sort
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Doctests
|
||||||
|
*
|
||||||
|
* > cocktailShakerSort([5, 4, 1, 2, 3])
|
||||||
|
* [1, 2, 3, 4, 5]
|
||||||
|
* > cocktailShakerSort([])
|
||||||
|
* []
|
||||||
|
* > cocktailShakerSort([1, 2, 3])
|
||||||
|
* [1, 2, 3]
|
||||||
|
*/
|
||||||
|
|
||||||
function cocktailShakerSort (items) {
|
function cocktailShakerSort (items) {
|
||||||
for (let i = items.length - 1; i > 0; i--) {
|
for (let i = items.length - 1; i > 0; i--) {
|
||||||
let j
|
let j
|
||||||
|
Reference in New Issue
Block a user