Skip to content

Commit 6c2f83b

Browse files
sukhpreetsekhonSukhpreet Sekhon
andauthored
Add doctest for QuickSort and MergeSort (#502)
* Add doctest for QuickSort * Add doctest for MergeSort Co-authored-by: Sukhpreet Sekhon <ssekhon@atb.com>
1 parent da28942 commit 6c2f83b

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

Sorts/MergeSort.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,27 @@
1313
* @param {Array} list2 - sublist to break down
1414
* @return {Array} merged list
1515
*/
16+
/*
17+
* Doctests
18+
* > merge([5, 4],[ 1, 2, 3])
19+
* [1, 2, 3, 5, 4]
20+
* > merge([],[1, 2])
21+
* [1, 2]
22+
* > merge([1, 2, 3], [1])
23+
* [1, 1, 2, 3]
24+
* > merge([], [])
25+
* []
26+
*
27+
* > mergeSort([5, 4])
28+
* [4, 5]
29+
* > mergeSort([8, 4, 10, 15, 9])
30+
* [4, 8, 9, 10, 15]
31+
* > mergeSort([1, 2, 3])
32+
* [1, 2, 3]
33+
* > mergeSort([ ])
34+
* [ ]
35+
*/
36+
1637
function merge (list1, list2) {
1738
var results = []
1839

Sorts/QuickSort.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,20 @@
22
* Quick sort is a comparison sorting algorithm that uses a divide and conquer strategy.
33
* For more information see here: https://en.wikipedia.org/wiki/Quicksort
44
*/
5+
6+
/*
7+
* Doctests
8+
*
9+
* > quickSort([5, 4, 3, 10, 2, 1])
10+
* [1, 2, 3, 4, 5, 10]
11+
* > quickSort([])
12+
* []
13+
* > quickSort([5, 4])
14+
* [4, 5]
15+
* > quickSort([1, 2, 3])
16+
* [1, 2, 3]
17+
*/
18+
519
function quickSort (items) {
620
var length = items.length
721

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy