Skip to content

Commit 9386c29

Browse files
authored
Merge pull request #534 from Khez/string-reverse-string
#142 #461 Adding Doctests to String/ReverseString.js
2 parents 1b7a15d + 6bc638b commit 9386c29

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

String/ReverseString.js

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,22 @@
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-
1125
function ReverseStringIterative (string) {
1226
if (typeof string !== 'string') {
1327
throw new TypeError('The given value is not a string')
@@ -25,11 +39,25 @@ 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-
3361
function ReverseStringIterativeInplace (string) {
3462
if (typeof string !== 'string') {
3563
throw new TypeError('The given value is not a string')

0 commit comments

Comments
 (0)