File tree Expand file tree Collapse file tree 1 file changed +31
-3
lines changed Expand file tree Collapse file tree 1 file changed +31
-3
lines changed Original file line number Diff line number Diff line change 6
6
/**
7
7
* Create a new string and append
8
8
* @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
9
24
*/
10
-
11
25
function ReverseStringIterative ( string ) {
12
26
if ( typeof string !== 'string' ) {
13
27
throw new TypeError ( 'The given value is not a string' )
@@ -25,11 +39,25 @@ function ReverseStringIterative (string) {
25
39
/**
26
40
* JS disallows string mutation so we're actually a bit slower.
27
41
*
28
- * @complexity : O(n)
42
+ * @complexity O(n)
29
43
*
30
44
* '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
31
60
*/
32
-
33
61
function ReverseStringIterativeInplace ( string ) {
34
62
if ( typeof string !== 'string' ) {
35
63
throw new TypeError ( 'The given value is not a string' )
You can’t perform that action at this time.
0 commit comments