-
-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[New Practice Exercise]: Reverse string (#713)
* Add reverse-string exercise * Fix json * Fix files
- Loading branch information
1 parent
a08f07a
commit f4870fe
Showing
11 changed files
with
150 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.DS_Store | ||
/.build | ||
/Packages | ||
/*.xcodeproj |
3 changes: 3 additions & 0 deletions
3
exercises/practice/reverse-string/.meta/Sources/ReverseString/ReverseStringExample.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
func reverseString(_ input : String) -> String { | ||
return String(input.reversed()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"authors": ["meatball133"], | ||
"files": { | ||
"solution": [ | ||
"Sources/ReverseString/ReverseString.swift" | ||
], | ||
"test": [ | ||
"Tests/ReverseStringTests/ReverseStringTests.swift" | ||
], | ||
"example": [ | ||
".meta/Sources/ReverseString/ReverseStringExample.swift" | ||
] | ||
}, | ||
"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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import XCTest | ||
@testable import {{exercise|camelCase}} | ||
class {{exercise|camelCase}}Tests: XCTestCase { | ||
let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false | ||
|
||
{% for case in cases %} | ||
{% if forloop.first -%} | ||
func test{{case.description |camelCase }}() { | ||
{% else -%} | ||
func test{{case.description |camelCase }}() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
{% endif -%} | ||
XCTAssertEqual(reverseString("{{case.input.value}}"), "{{case.expected}}") | ||
} | ||
{% endfor -%} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// swift-tools-version:5.3 | ||
|
||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "ReverseString", | ||
products: [ | ||
.library( | ||
name: "ReverseString", | ||
targets: ["ReverseString"]) | ||
], | ||
dependencies: [], | ||
targets: [ | ||
.target( | ||
name: "ReverseString", | ||
dependencies: []), | ||
.testTarget( | ||
name: "ReverseStringTests", | ||
dependencies: ["ReverseString"]), | ||
] | ||
) |
3 changes: 3 additions & 0 deletions
3
exercises/practice/reverse-string/Sources/ReverseString/ReverseString.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
func reverseString(_ input : String) -> String { | ||
// Write your code for the 'Reverse String' exercise in this file. | ||
} |
36 changes: 36 additions & 0 deletions
36
exercises/practice/reverse-string/Tests/ReverseStringTests/ReverseStringTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import XCTest | ||
|
||
@testable import ReverseString | ||
|
||
class ReverseStringTests: XCTestCase { | ||
let runAll = Bool(ProcessInfo.processInfo.environment["RUNALL", default: "false"]) ?? false | ||
|
||
func testAnEmptyString() { | ||
XCTAssertEqual(reverseString(""), "") | ||
} | ||
|
||
func testAWord() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
XCTAssertEqual(reverseString("robot"), "tobor") | ||
} | ||
|
||
func testACapitalizedWord() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
XCTAssertEqual(reverseString("Ramen"), "nemaR") | ||
} | ||
|
||
func testASentenceWithPunctuation() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
XCTAssertEqual(reverseString("I'm hungry!"), "!yrgnuh m'I") | ||
} | ||
|
||
func testAPalindrome() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
XCTAssertEqual(reverseString("racecar"), "racecar") | ||
} | ||
|
||
func testAnEvenSizedWord() throws { | ||
try XCTSkipIf(true && !runAll) // change true to false to run this test | ||
XCTAssertEqual(reverseString("drawer"), "reward") | ||
} | ||
} |