Skip to content

Commit 2d66526

Browse files
authored
Syncing test.toml and updating the test code for reverse-string (#2648)
* Syncing test.toml and updating the test code * Updating proof solution * Running prettier * Skipping the tests requiring segmenter * Adding instructions.append.md * Adding prettier ignore
1 parent 564aca4 commit 2d66526

File tree

5 files changed

+50
-5
lines changed

5 files changed

+50
-5
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<!-- prettier-ignore-start -->
2+
~~~exercism/advanced
3+
If you solve this using the CLI, there are test cases that require you to deal with complex characters.
4+
You can optionally enable these tests by removing `.skip` from the test.
5+
~~~
6+
<!-- prettier-ignore-end -->

exercises/practice/reverse-string/.meta/config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"contributors": [
66
"ankorGH",
77
"d-vail",
8+
"jagdish-15",
89
"ovidiu141",
910
"SleeplessByte"
1011
],
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
export const reverseString = (string) => {
22
let revString = '';
3-
for (let i = string.length - 1; i >= 0; i -= 1) {
4-
revString += string[i];
3+
let characters = Array.from(
4+
new Intl.Segmenter().segment(String(string)),
5+
(x) => x.segment,
6+
);
7+
for (let i = characters.length - 1; i >= 0; i--) {
8+
revString += characters[i];
59
}
610
return revString;
711
};

exercises/practice/reverse-string/.meta/tests.toml

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1-
# This is an auto-generated file. Regular comments will be removed when this
2-
# file is regenerated. Regenerating will not touch any manually added keys,
3-
# so comments can be added in a "comment" key.
1+
# This is an auto-generated file.
2+
#
3+
# Regenerating this file via `configlet sync` will:
4+
# - Recreate every `description` key/value pair
5+
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
6+
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
7+
# - Preserve any other key/value pair
8+
#
9+
# As user-added comments (using the # character) will be removed when this file
10+
# is regenerated, comments can be added via a `comment` key.
411

512
[c3b7d806-dced-49ee-8543-933fd1719b1c]
613
description = "an empty string"
@@ -19,3 +26,12 @@ description = "a palindrome"
1926

2027
[b9e7dec1-c6df-40bd-9fa3-cd7ded010c4c]
2128
description = "an even-sized word"
29+
30+
[1bed0f8a-13b0-4bd3-9d59-3d0593326fa2]
31+
description = "wide characters"
32+
33+
[93d7e1b8-f60f-4f3c-9559-4056e10d2ead]
34+
description = "grapheme cluster with pre-combined form"
35+
36+
[1028b2c1-6763-4459-8540-2da47ca512d9]
37+
description = "grapheme clusters"

exercises/practice/reverse-string/reverse-string.spec.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,22 @@ describe('ReverseString', () => {
3737
const actual = reverseString('drawer');
3838
expect(actual).toEqual(expected);
3939
});
40+
41+
xtest('wide characters', () => {
42+
const expected = '猫子';
43+
const actual = reverseString('子猫');
44+
expect(actual).toEqual(expected);
45+
});
46+
47+
test.skip('grapheme cluster with pre-combined form', () => {
48+
const expected = 'dnatsnehctsrüW';
49+
const actual = reverseString('Würstchenstand');
50+
expect(actual).toEqual(expected);
51+
});
52+
53+
test.skip('grapheme clusters', () => {
54+
const expected = 'มรกแรปโนยขีเผู้';
55+
const actual = reverseString('ผู้เขียนโปรแกรม');
56+
expect(actual).toEqual(expected);
57+
});
4058
});

0 commit comments

Comments
 (0)