Skip to content

#142 #461 Adding Doctests to String/ReverseString.js #534

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 20, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 31 additions & 3 deletions String/ReverseString.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,22 @@
/**
* 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) {
if (typeof string !== 'string') {
throw new TypeError('The given value is not a string')
Expand All @@ -25,11 +39,25 @@ 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) {
if (typeof string !== 'string') {
throw new TypeError('The given value is not a string')
Expand Down