Skip to content
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

[reverse-string] Implementation #628

Merged
merged 7 commits into from
Jun 24, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,15 @@
"prerequisites": [],
"difficulty": 1,
"topics": []
},
{
"slug": "reverse-string",
"name": "Reverse String",
"uuid": "cdc17b6c-ccde-4709-9bbe-a5af7a79b8ae",
"practices": [],
"prerequisites": [],
"difficulty": 1,
"topics": []
}
]
},
Expand Down
7 changes: 7 additions & 0 deletions exercises/practice/reverse-string/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Instructions

Reverse a string

For example:
input: "cool"
output: "looc"
19 changes: 19 additions & 0 deletions exercises/practice/reverse-string/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"authors": [
"habere-et-dispertire"
],
"files": {
"solution": [
"ReverseString.rakumod"
],
"test": [
"reverse-string.rakutest"
],
"example": [
".meta/solutions/ReverseString.rakumod"
]
},
"blurb": "Reverse a 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"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
unit module ReverseString;

sub switch-round($string) is export {
$string.flip
}
27 changes: 27 additions & 0 deletions exercises/practice/reverse-string/.meta/template-data.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
properties:
reverse:
test: |-
sprintf(q:to/END/, %case<input><value>.raku, %case<expected>.raku, %case<description>.raku, %case<input><value>.raku, %case<input><value>.raku, %case<description>.raku);
cmp-ok(
switch-round(%s),
"eq",
%s,
%s,
) &&
cmp-ok(
switch-round(switch-round(%s)),
"eq",
%s,
%s,
);
END

unit: module
example: |-
sub switch-round($string) is export {
$string.flip
}

stub: |-
sub switch-round($string) is export {
habere-et-dispertire marked this conversation as resolved.
Show resolved Hide resolved
}
28 changes: 28 additions & 0 deletions exercises/practice/reverse-string/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# This is an auto-generated file.
#
# Regenerating this file via `configlet sync` will:
# - Recreate every `description` key/value pair
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
# - Preserve any other key/value pair
#
# As user-added comments (using the # character) will be removed when this file
# is regenerated, comments can be added via a `comment` key.

[c3b7d806-dced-49ee-8543-933fd1719b1c]
description = "an empty string"

[01ebf55b-bebb-414e-9dec-06f7bb0bee3c]
description = "a word"

[0f7c07e4-efd1-4aaa-a07a-90b49ce0b746]
description = "a capitalized word"

[71854b9c-f200-4469-9f5c-1e8e5eff5614]
description = "a sentence with punctuation"

[1f8ed2f3-56f3-459b-8f3e-6d8d654a1f6c]
description = "a palindrome"

[b9e7dec1-c6df-40bd-9fa3-cd7ded010c4c]
description = "an even-sized word"
4 changes: 4 additions & 0 deletions exercises/practice/reverse-string/ReverseString.rakumod
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
unit module ReverseString;

sub switch-round($string) is export {
}
84 changes: 84 additions & 0 deletions exercises/practice/reverse-string/reverse-string.rakutest
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!/usr/bin/env raku
use Test;
use lib $?FILE.IO.dirname;
use ReverseString;

cmp-ok( # begin: c3b7d806-dced-49ee-8543-933fd1719b1c
switch-round(""),
"eq",
"",
"an empty string",
) &&
habere-et-dispertire marked this conversation as resolved.
Show resolved Hide resolved
cmp-ok(
switch-round(switch-round("")),
"eq",
"",
"an empty string",
); # end: c3b7d806-dced-49ee-8543-933fd1719b1c

cmp-ok( # begin: 01ebf55b-bebb-414e-9dec-06f7bb0bee3c
switch-round("robot"),
"eq",
"tobor",
"a word",
) &&
cmp-ok(
switch-round(switch-round("robot")),
"eq",
"robot",
"a word",
); # end: 01ebf55b-bebb-414e-9dec-06f7bb0bee3c

cmp-ok( # begin: 0f7c07e4-efd1-4aaa-a07a-90b49ce0b746
switch-round("Ramen"),
"eq",
"nemaR",
"a capitalized word",
) &&
cmp-ok(
switch-round(switch-round("Ramen")),
"eq",
"Ramen",
"a capitalized word",
); # end: 0f7c07e4-efd1-4aaa-a07a-90b49ce0b746

cmp-ok( # begin: 71854b9c-f200-4469-9f5c-1e8e5eff5614
switch-round("I'm hungry!"),
"eq",
"!yrgnuh m'I",
"a sentence with punctuation",
) &&
cmp-ok(
switch-round(switch-round("I'm hungry!")),
"eq",
"I'm hungry!",
"a sentence with punctuation",
); # end: 71854b9c-f200-4469-9f5c-1e8e5eff5614

cmp-ok( # begin: 1f8ed2f3-56f3-459b-8f3e-6d8d654a1f6c
switch-round("racecar"),
"eq",
"racecar",
"a palindrome",
) &&
cmp-ok(
switch-round(switch-round("racecar")),
"eq",
"racecar",
"a palindrome",
); # end: 1f8ed2f3-56f3-459b-8f3e-6d8d654a1f6c

cmp-ok( # begin: b9e7dec1-c6df-40bd-9fa3-cd7ded010c4c
switch-round("drawer"),
"eq",
"reward",
"an even-sized word",
) &&
cmp-ok(
switch-round(switch-round("drawer")),
"eq",
"drawer",
"an even-sized word",
); # end: b9e7dec1-c6df-40bd-9fa3-cd7ded010c4c

done-testing;