Skip to content

Commit

Permalink
Add reverse-string
Browse files Browse the repository at this point in the history
  • Loading branch information
colinleach committed Jan 6, 2024
1 parent 872df5b commit 76205f1
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 0 deletions.
8 changes: 8 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,14 @@
"topics": [
"math"
]
},
{
"slug": "reverse-string",
"name": "Reverse String",
"uuid": "684e330d-7ee6-4151-9fc3-c1ca376136c3",
"practices": [],
"prerequisites": [],
"difficulty": 1
}
]
},
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"
20 changes: 20 additions & 0 deletions exercises/practice/reverse-string/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"authors": [
"colinleach",
"jonmcalder"
],
"files": {
"solution": [
"reverse-string.R"
],
"test": [
"test_reverse-string.R"
],
"example": [
".meta/example.R"
]
},
"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"
}
5 changes: 5 additions & 0 deletions exercises/practice/reverse-string/.meta/example.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
reverse <- function(text) {
splits <- strsplit(text, "")[[1]]
reversed <- rev(splits)
paste(reversed, collapse = "")
}
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"
3 changes: 3 additions & 0 deletions exercises/practice/reverse-string/reverse-string.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
reverse <- function(text) {

}
27 changes: 27 additions & 0 deletions exercises/practice/reverse-string/test_reverse-string.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
source("./reverse-string.R")
library(testthat)

test_that("an empty string", {
expect_equal(reverse(""), "")
})

test_that("a word", {
expect_equal(reverse("robot"), "tobor")
})

test_that("a capitalized word", {
expect_equal(reverse("Ramen"), "nemaR")
})

test_that("a sentence with punctuation", {
expect_equal(reverse("I'm hungry!"), "!yrgnuh m'I")
})

test_that("a palindrome", {
expect_equal(reverse("racecar"), "racecar")
})

test_that("an even-sized word", {
expect_equal(reverse("drawer"), "reward")
})

0 comments on commit 76205f1

Please sign in to comment.