Skip to content

Commit 84e4c99

Browse files
committed
#142 #461 Adding Doctests to String/ReverseString.js
1 parent 2190b92 commit 84e4c99

File tree

1 file changed

+33
-5
lines changed

1 file changed

+33
-5
lines changed

String/ReverseString.js

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,23 @@
66
/**
77
* Create a new string and append
88
* @complexity O(n)
9+
*
10+
* Doctests
11+
*
12+
* > ReverseStringIterative('some')
13+
* 'emos'
14+
* > ReverseStringIterative('string')
15+
* 'gnirts'
16+
* > ReverseStringIterative('The Algorithms Javascript')
17+
* 'tpircsavaJ smhtiroglA ehT'
18+
* > ReverseStringIterative([])
19+
* ! TypeError
20+
* > ReverseStringIterative({})
21+
* ! TypeError
22+
* > ReverseStringIterative(null)
23+
* ! TypeError
924
*/
10-
11-
function ReverseStringIterative (string) {
25+
function ReverseStringIterative(string) {
1226
if (typeof string !== 'string') {
1327
throw new TypeError('The given value is not a string')
1428
}
@@ -25,12 +39,26 @@ function ReverseStringIterative (string) {
2539
/**
2640
* JS disallows string mutation so we're actually a bit slower.
2741
*
28-
* @complexity: O(n)
42+
* @complexity O(n)
2943
*
3044
* 'some' -> 'eoms' -> 'emos'
45+
*
46+
* Doctests
47+
*
48+
* > ReverseStringIterativeInplace('some')
49+
* 'emos'
50+
* > ReverseStringIterativeInplace('string')
51+
* 'gnirts'
52+
* > ReverseStringIterativeInplace('The Algorithms Javascript')
53+
* 'tpircsavaJ smhtiroglA ehT'
54+
* > ReverseStringIterativeInplace([])
55+
* ! TypeError
56+
* > ReverseStringIterativeInplace({})
57+
* ! TypeError
58+
* > ReverseStringIterativeInplace(null)
59+
* ! TypeError
3160
*/
32-
33-
function ReverseStringIterativeInplace (string) {
61+
function ReverseStringIterativeInplace(string) {
3462
if (typeof string !== 'string') {
3563
throw new TypeError('The given value is not a string')
3664
}

0 commit comments

Comments
 (0)