Skip to content

reverse-string: Add new exercise #960

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 20 commits into from
Nov 11, 2017
Merged
Show file tree
Hide file tree
Changes from 19 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
39 changes: 39 additions & 0 deletions exercises/reverse-string/canonical-data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"exercise": "reverse-string",
"version": "1.0.0",
"comments": [
"If property based testing tools are available, a good property to test is reversing a string twice: reverse(reverse(string)) == string"
],
"cases": [
{
"description": "empty string",
"property": "reverse",
"input": "",
"expected": ""
},
{
"description": "a word",
"property": "reverse",
"input": "robot",
"expected": "tobor"
},
{
"description": "a capitalized word",
"property": "reverse",
"input": "Ramen",
"expected": "nemaR"
},
{
"description": "a sentence with punctuation",
"property": "reverse",
"input": "I'm hungry!",
"expected": "!yrgnuh m'I"
},
{
"description": "a string that reads the same backward as forward (i.e. palindrome)",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you defining palindrome here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think everybody knows what a palindrome is, and personally, I'd rather have it defined here than have to google it. If you feel strongly we don't need to define it, please state why you think everybody knows this. Perhaps wording can change some.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Continuing discussion from: #960 (comment)

It is helpful for descriptions to be short and to the point, so either

"a string that reads the same backwards and forwards"
or
"a palindrome"

but not both.

My preference is for "a palindrome", because that is the briefest description of what it is.
It's still possible to solve the problem without knowing the definition of the word and the definition can easily be found by a search if necessary.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To give a concrete example of why concision is useful, consider the output of programs which generate tests based on the canonical data. Which is best:

  • fn test_a_palindrome() { ... }
  • fn test_a_string_that_reads_the_same_backwards_and_forwards() { ... }
  • fn test_a_string_that_reads_the_same_backward_as_forward_ie_palindrome() { ... }

Depending on which option gets merged, the Rust test generator will create one of the above. IMO, the shortest is the best.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I'm convinced. I added just "a palindrome" for description to latest commit.

Please review @Insti. Thanks.

"property": "reverse",
"input": "racecar",
"expected": "racecar"
}
]
}
5 changes: 5 additions & 0 deletions exercises/reverse-string/description.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Reverse a string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Short description is good 👍

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, short and to the point!


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This description contains too many instructions.
The description should just describe what the problem is.

It would be fine to include some background on what a 'string' is.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be fine to include some background on what a 'string' is.

This is hard in a language agnostic way…

I think the most agnostic way were to say "its an ordered sequence of characters".

But even this description might fail if you accept BEAMs io-lists as strings…

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is hard in a language agnostic way…

I agree, which makes me think even including the word "string" is a bad idea.

maybe 'text' or 'words' or 'snippet' or 'sentence' or something else..?

For example:
input: "cool"
output: "looc"
5 changes: 5 additions & 0 deletions exercises/reverse-string/metadata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
blurb: "Reverse a string"
title: "reverse-string"
source: "Introductory challenge to reverse an input string"
source_url: "https://medium.freecodecamp.org/how-to-reverse-a-string-in-javascript-in-3-different-ways-75e4763c68cb"