From 84e4c9906be3392032d98c5b719bdb3491b2b17a Mon Sep 17 00:00:00 2001 From: Cristian Lupu Date: Fri, 30 Oct 2020 18:24:34 +0200 Subject: [PATCH 1/2] #142 #461 Adding Doctests to String/ReverseString.js --- String/ReverseString.js | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/String/ReverseString.js b/String/ReverseString.js index b0342e5a61..6ce861ce9e 100644 --- a/String/ReverseString.js +++ b/String/ReverseString.js @@ -6,9 +6,23 @@ /** * Create a new string and append * @complexity O(n) + * + * Doctests + * + * > ReverseStringIterative('some') + * 'emos' + * > ReverseStringIterative('string') + * 'gnirts' + * > ReverseStringIterative('The Algorithms Javascript') + * 'tpircsavaJ smhtiroglA ehT' + * > ReverseStringIterative([]) + * ! TypeError + * > ReverseStringIterative({}) + * ! TypeError + * > ReverseStringIterative(null) + * ! TypeError */ - -function ReverseStringIterative (string) { +function ReverseStringIterative(string) { if (typeof string !== 'string') { throw new TypeError('The given value is not a string') } @@ -25,12 +39,26 @@ function ReverseStringIterative (string) { /** * JS disallows string mutation so we're actually a bit slower. * - * @complexity: O(n) + * @complexity O(n) * * 'some' -> 'eoms' -> 'emos' + * + * Doctests + * + * > ReverseStringIterativeInplace('some') + * 'emos' + * > ReverseStringIterativeInplace('string') + * 'gnirts' + * > ReverseStringIterativeInplace('The Algorithms Javascript') + * 'tpircsavaJ smhtiroglA ehT' + * > ReverseStringIterativeInplace([]) + * ! TypeError + * > ReverseStringIterativeInplace({}) + * ! TypeError + * > ReverseStringIterativeInplace(null) + * ! TypeError */ - -function ReverseStringIterativeInplace (string) { +function ReverseStringIterativeInplace(string) { if (typeof string !== 'string') { throw new TypeError('The given value is not a string') } From 6bc638b34ec1860efb2601bab26563a45f6086e3 Mon Sep 17 00:00:00 2001 From: Cristian Lupu Date: Fri, 30 Oct 2020 18:28:29 +0200 Subject: [PATCH 2/2] StandardJS Checks require space after function name --- String/ReverseString.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/String/ReverseString.js b/String/ReverseString.js index 6ce861ce9e..5ced8b35cf 100644 --- a/String/ReverseString.js +++ b/String/ReverseString.js @@ -22,7 +22,7 @@ * > ReverseStringIterative(null) * ! TypeError */ -function ReverseStringIterative(string) { +function ReverseStringIterative (string) { if (typeof string !== 'string') { throw new TypeError('The given value is not a string') } @@ -58,7 +58,7 @@ function ReverseStringIterative(string) { * > ReverseStringIterativeInplace(null) * ! TypeError */ -function ReverseStringIterativeInplace(string) { +function ReverseStringIterativeInplace (string) { if (typeof string !== 'string') { throw new TypeError('The given value is not a string') }