Skip to content

Commit

Permalink
Implement exercise 'reverse-string'
Browse files Browse the repository at this point in the history
  • Loading branch information
ingydotnet committed Jul 29, 2024
1 parent 1293cd9 commit 68217a5
Show file tree
Hide file tree
Showing 11 changed files with 137 additions and 0 deletions.
8 changes: 8 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@
"practices": [],
"prerequisites": [],
"difficulty": 1
},
{
"slug": "reverse-string",
"name": "Reverse String",
"uuid": "89681570-5734-4f20-b68f-de8b176accdc",
"practices": [],
"prerequisites": [],
"difficulty": 1
}
]
},
Expand Down
7 changes: 7 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ exercises:
prerequisites: []
difficulty: 1

- slug: reverse-string
name: Reverse String
uuid: 89681570-5734-4f20-b68f-de8b176accdc
practices: []
prerequisites: []
difficulty: 1

tags:
- execution_mode/compiled
- execution_mode/interpreted
Expand Down
9 changes: 9 additions & 0 deletions exercises/practice/reverse-string/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Instructions

Your task is to reverse a given string.

Some examples:

- Turn `"stressed"` into `"desserts"`.
- Turn `"strops"` into `"sports"`.
- Turn `"racecar"` into `"racecar"`.
5 changes: 5 additions & 0 deletions exercises/practice/reverse-string/.docs/introduction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Introduction

Reversing strings (reading them from right to left, rather than from left to right) is a surprisingly common task in programming.

For example, in bioinformatics, reversing the sequence of DNA or RNA strings is often important for various analyses, such as finding complementary strands or identifying palindromic sequences that have biological significance.
18 changes: 18 additions & 0 deletions exercises/practice/reverse-string/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"authors": [],
"files": {
"solution": [
"reverse-string.ys"
],
"test": [
"test/test-1.ys",
"Makefile"
],
"example": [
".meta/reverse-string.ys"
]
},
"blurb": "Reverse a given 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"
}
4 changes: 4 additions & 0 deletions exercises/practice/reverse-string/.meta/reverse-string.ys
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
!yamlscript/v0

defn reverse-string(s):
str/reverse: s
1 change: 1 addition & 0 deletions exercises/practice/reverse-string/.meta/test
40 changes: 40 additions & 0 deletions exercises/practice/reverse-string/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# 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"

[1bed0f8a-13b0-4bd3-9d59-3d0593326fa2]
description = "wide characters"
include = false

[93d7e1b8-f60f-4f3c-9559-4056e10d2ead]
description = "grapheme cluster with pre-combined form"
include = false

[1028b2c1-6763-4459-8540-2da47ca512d9]
description = "grapheme clusters"
include = false
9 changes: 9 additions & 0 deletions exercises/practice/reverse-string/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
SHELL := bash

export YSPATH=$(PWD)

default:

.PHONY: test
test:
prove -v test/*.ys
4 changes: 4 additions & 0 deletions exercises/practice/reverse-string/reverse-string.ys
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
!yamlscript/v0

defn reverse-string(s): # <- arglist goes here
your code: goes here
32 changes: 32 additions & 0 deletions exercises/practice/reverse-string/test/test-1.ys
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env ys-0

require ys::taptest: :all

use: reverse-string

test::
- name: An empty string
code: reverse-string('')
want: ''

- name: A word
code: reverse-string('robot')
want: tobor

- name: A capitalized word
code: reverse-string('Ramen')
want: nemaR

- name: A sentence with punctuation
code: reverse-string("I'm hungry!")
want: "!yrgnuh m'I"

- name: A palindrome
code: reverse-string('racecar')
want: racecar

- name: An even sized word
code: reverse-string('drawer')
want: reward

done:

0 comments on commit 68217a5

Please sign in to comment.