Skip to content

Commit 2bf78fb

Browse files
committed
Reverse String: move unicode extensions to exercises
Move the unicode bonus to the exercises instead of the description. This will allow the exercises to automatically be brought into the various tracks. I was originally going to use πŸ‘πŸ½ as the grapheme example. But as it is split in my terminal (Gnome Terminal) and my editor (Visual Studio Code), I presume it would be split for most students. Displaying it split might make it confusing.
1 parent 6d2b21a commit 2bf78fb

File tree

2 files changed

+62
-29
lines changed

2 files changed

+62
-29
lines changed

β€Žexercises/reverse-string/canonical-data.json

Lines changed: 62 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"exercise": "reverse-string",
3-
"version": "1.1.0",
3+
"version": "1.1.0",
44
"comments": [
5-
"If property based testing tools are available, a good property to test is reversing a string twice: reverse(reverse(string)) == string"
6-
],
5+
"If property based testing tools are available, a good property to test is reversing a string twice: reverse(reverse(string)) == string"
6+
],
77
"cases": [
88
{
99
"description": "an empty string",
@@ -31,7 +31,7 @@
3131
},
3232
{
3333
"description": "a sentence with punctuation",
34-
"property": "reverse",
34+
"property": "reverse",
3535
"input": {
3636
"value": "I'm hungry!"
3737
},
@@ -44,6 +44,63 @@
4444
"value": "racecar"
4545
},
4646
"expected": "racecar"
47+
},
48+
{
49+
"comments": [
50+
"Track Maintainers:",
51+
"Please remove this example if your language has poor unicode support.",
52+
"This will probably work immediately in languages that use UTF-16 for",
53+
"their strings."
54+
],
55+
"description": "wide characters",
56+
"property": "reverse",
57+
"input": {
58+
"value": "子猫"
59+
},
60+
"expected": "猫子"
61+
},
62+
{
63+
"comments": [
64+
"Track Maintainers:",
65+
"Please remove this example if your language has poor unicode support.",
66+
"If you chose to use this exercise, consider marking it as a bonus.",
67+
"",
68+
"Students:",
69+
"You may find you have been splitting on Unicode code units. If this",
70+
"isn't passing, look into splitting on Unicode characters."
71+
],
72+
"description": "ultra wide characters",
73+
"property": "reverse",
74+
"input": {
75+
"value": "πŸ˜€β˜•"
76+
},
77+
"expected": "β˜•πŸ˜€"
78+
},
79+
{
80+
"comments": [
81+
"Track Maintainers:",
82+
"Please remove this example if your language does not support Unicode",
83+
"Text Segmentation (Grapheme Clusters) or have good third party",
84+
"libraries for it. If not natively supported by the language, please",
85+
"encourage students to use a library.",
86+
"If you chose to use this exercise, consider marking it as a bonus.",
87+
"",
88+
"Students:",
89+
"Some printed characters are actually made up of multiple unicode",
90+
"characters. For example, the Latin Small Letter U with Diaeresis (ü),",
91+
"is made up of Latin Small Letter U (u) followed by the Diaeresis",
92+
"modifier. Together they make up a Grapheme cluster (user-perceived",
93+
"character).",
94+
"",
95+
"When reversing a string, we want to keep the order of the characters",
96+
"within the grapheme."
97+
],
98+
"description": "grapheme clusters",
99+
"property": "reverse",
100+
"input": {
101+
"value": "uüu"
102+
},
103+
"expected": "uüu"
47104
}
48105
]
49-
}
106+
}

β€Žexercises/reverse-string/description.md

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,3 @@ Reverse a string
33
For example:
44
input: "cool"
55
output: "looc"
6-
7-
## For bonus points
8-
9-
Did you get the tests passing and the code clean? If you want to, these
10-
are some additional things you could try:
11-
12-
- ASCII, UTF-8 and UTF-16 are 3 common character encodings you are likely to
13-
encounter as a programmer. ASCII is a character encoding published in 1963
14-
designed for representing English language text. UTF-8 and UTF-16 are both
15-
Unicode character encodings. Unicode was first published in 1991 and can now
16-
represent English language text, foreign text, historic text and emojis.
17-
18-
UTF-8 and UTF-16 both represent English language characters as a single code
19-
unit. But many emoji characters require 2 or more code units.
20-
21-
Add a test for reversing a string of a couple emoji characters. You may find
22-
that your existing solution has been reversing bytes or code units instead of
23-
characters.
24-
25-
Here is an example emoji string: πŸ˜€β˜•
26-
And its reverse: β˜•πŸ˜€
27-
28-
Note that some languages are not Unicode aware. It is not recommended to try
29-
this challenge if your language does not have good Unicode support.

0 commit comments

Comments
Β (0)