From 76205f1b3202724a3aafaf1977cc51b2c77ee865 Mon Sep 17 00:00:00 2001 From: colinleach Date: Sat, 6 Jan 2024 11:49:46 -0700 Subject: [PATCH] Add reverse-string --- config.json | 8 ++++++ .../reverse-string/.docs/instructions.md | 7 +++++ .../practice/reverse-string/.meta/config.json | 20 +++++++++++++ .../practice/reverse-string/.meta/example.R | 5 ++++ .../practice/reverse-string/.meta/tests.toml | 28 +++++++++++++++++++ .../practice/reverse-string/reverse-string.R | 3 ++ .../reverse-string/test_reverse-string.R | 27 ++++++++++++++++++ 7 files changed, 98 insertions(+) create mode 100644 exercises/practice/reverse-string/.docs/instructions.md create mode 100644 exercises/practice/reverse-string/.meta/config.json create mode 100644 exercises/practice/reverse-string/.meta/example.R create mode 100644 exercises/practice/reverse-string/.meta/tests.toml create mode 100644 exercises/practice/reverse-string/reverse-string.R create mode 100644 exercises/practice/reverse-string/test_reverse-string.R diff --git a/config.json b/config.json index ae9cb02d..75a59dc6 100644 --- a/config.json +++ b/config.json @@ -593,6 +593,14 @@ "topics": [ "math" ] + }, + { + "slug": "reverse-string", + "name": "Reverse String", + "uuid": "684e330d-7ee6-4151-9fc3-c1ca376136c3", + "practices": [], + "prerequisites": [], + "difficulty": 1 } ] }, diff --git a/exercises/practice/reverse-string/.docs/instructions.md b/exercises/practice/reverse-string/.docs/instructions.md new file mode 100644 index 00000000..039ee33a --- /dev/null +++ b/exercises/practice/reverse-string/.docs/instructions.md @@ -0,0 +1,7 @@ +# Instructions + +Reverse a string + +For example: +input: "cool" +output: "looc" diff --git a/exercises/practice/reverse-string/.meta/config.json b/exercises/practice/reverse-string/.meta/config.json new file mode 100644 index 00000000..659ae0a7 --- /dev/null +++ b/exercises/practice/reverse-string/.meta/config.json @@ -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" +} diff --git a/exercises/practice/reverse-string/.meta/example.R b/exercises/practice/reverse-string/.meta/example.R new file mode 100644 index 00000000..b3fddc63 --- /dev/null +++ b/exercises/practice/reverse-string/.meta/example.R @@ -0,0 +1,5 @@ +reverse <- function(text) { + splits <- strsplit(text, "")[[1]] + reversed <- rev(splits) + paste(reversed, collapse = "") +} \ No newline at end of file diff --git a/exercises/practice/reverse-string/.meta/tests.toml b/exercises/practice/reverse-string/.meta/tests.toml new file mode 100644 index 00000000..0b04c4cd --- /dev/null +++ b/exercises/practice/reverse-string/.meta/tests.toml @@ -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" diff --git a/exercises/practice/reverse-string/reverse-string.R b/exercises/practice/reverse-string/reverse-string.R new file mode 100644 index 00000000..1766d104 --- /dev/null +++ b/exercises/practice/reverse-string/reverse-string.R @@ -0,0 +1,3 @@ +reverse <- function(text) { + +} \ No newline at end of file diff --git a/exercises/practice/reverse-string/test_reverse-string.R b/exercises/practice/reverse-string/test_reverse-string.R new file mode 100644 index 00000000..9be1132a --- /dev/null +++ b/exercises/practice/reverse-string/test_reverse-string.R @@ -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") +}) +