Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
10 changes: 6 additions & 4 deletions exercises/practice/reverse-string/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Instructions

Reverse a string
Your task is to reverse a given string.

For example:
input: "cool"
output: "looc"
Some examples:

- Turn `"stressed"` into `"desserts"`.
- Turn `"strops"` into `"sports"`.
- Turn `"racecar"` into `"racecar"`.
5 changes: 5 additions & 0 deletions exercises/practice/reverse-string/.docs/introduction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Introduction

Reversing strings (reading them from right to left, rather than from left to right) is a surprisingly common task in programming.

For example, in bioinformatics, reversing the sequence of DNA or RNA strings is often important for various analyses, such as finding complementary strands or identifying palindromic sequences that have biological significance.
11 changes: 6 additions & 5 deletions exercises/practice/reverse-string/.meta/example.gd
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Probably a good candidate to add a hints.md given the trick needed to pass the new tests.

Copy link
Member

Choose a reason for hiding this comment

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

You can't see hints in the web editor for practice exercises, so I think it is better to put them in an instruction append doc if needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, thanks!

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
func reverse(str):
var result = ""
for i in range(str.length() - 1, -1, -1):
result += str[i]
return result
func reverse(original):
var regex = RegEx.new()
regex.compile("\\X")
var clusters = regex.search_all(original).map(func(m): return m.get_string())
clusters.reverse()
return "".join(clusters)
9 changes: 9 additions & 0 deletions exercises/practice/reverse-string/.meta/tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,12 @@ description = "a palindrome"

[b9e7dec1-c6df-40bd-9fa3-cd7ded010c4c]
description = "an even-sized word"

[1bed0f8a-13b0-4bd3-9d59-3d0593326fa2]
description = "wide characters"

[93d7e1b8-f60f-4f3c-9559-4056e10d2ead]
description = "grapheme cluster with pre-combined form"

[1028b2c1-6763-4459-8540-2da47ca512d9]
description = "grapheme clusters"
44 changes: 31 additions & 13 deletions exercises/practice/reverse-string/reverse_string_test.gd
Original file line number Diff line number Diff line change
@@ -1,34 +1,52 @@
func test_empty_string(solution_script):
var str = ""
func test_empty_originaling(solution_script):
var original = ""
var expected = ""
return [solution_script.reverse(str), expected]
return [solution_script.reverse(original), expected]


func test_a_word(solution_script):
var str = "robot"
var original = "robot"
var expected = "tobor"
return [solution_script.reverse(str), expected]
return [solution_script.reverse(original), expected]


func test_a_capitalized_word(solution_script):
var str = "Ramen"
var original = "Ramen"
var expected = "nemaR"
return [solution_script.reverse(str), expected]
return [solution_script.reverse(original), expected]


func test_a_sentence_with_punctuation(solution_script):
var str = "I'm hungry!"
var original = "I'm hungry!"
var expected = "!yrgnuh m'I"
return [solution_script.reverse(str), expected]
return [solution_script.reverse(original), expected]


func test_a_palindrome(solution_script):
var str = "racecar"
var original = "racecar"
var expected = "racecar"
return [solution_script.reverse(str), expected]
return [solution_script.reverse(original), expected]


func test_an_even_sized_word(solution_script):
var str = "drawer"
var original = "drawer"
var expected = "reward"
return [solution_script.reverse(str), expected]
return [solution_script.reverse(original), expected]


func test_wide_characters(solution_script):
var original = "子猫"
var expected = "猫子"
return [solution_script.reverse(original), expected]


func test_grapheme_cluster_with_pre_combined_form(solution_script):
var original = "Würstchenstand"
var expected = "dnatsnehctsrüW"
return [solution_script.reverse(original), expected]


func test_grapheme_clusters(solution_script):
var original = "ผู้เขียนโปรแกรม"
var expected = "มรกแรปโนยขีเผู้"
return [solution_script.reverse(original), expected]