diff --git a/config.json b/config.json index aa778fbd..96db43df 100644 --- a/config.json +++ b/config.json @@ -57,6 +57,16 @@ "basics" ], "status": "wip" + }, + { + "slug": "squeaky-clean", + "name": "squeaky-clean", + "uuid": "7c06c4e8-4bc1-42c3-982a-f973f45193bf", + "concepts": [ + "chars" + ], + "prerequisites": [], + "status": "wip" } ], "practice": [ diff --git a/exercises/concept/squeaky-clean/.docs/hints.md b/exercises/concept/squeaky-clean/.docs/hints.md new file mode 100644 index 00000000..02c0b699 --- /dev/null +++ b/exercises/concept/squeaky-clean/.docs/hints.md @@ -0,0 +1,32 @@ +# Hints + +## 1. Replace any spaces encountered with underscores + +- [Reference documentation][char-docs] for `Char`s is here. +- `Char` literals are enclosed in 'single quotes', `String` literals in "double quotes". + +## 2. Remove all whitespace + +- See [this method][isspace] for detecting whitespace characters and [this method][isdigit] for digits. + +## 3. Convert camel-case to kebab-case + +- See [this method][isuppercase] to check if a character is case. +- See [this method][lowercase] to convert a character to lower case. + +## 5. Omit Greek lower case letters + +- `Char`s support the default equality and comparison operators. + +## 6. Combine these operations to operate on a string + +- A string can be iterated over, in the same way as an array. +- To do all the transforms, consider using a comprehension. +- Multiple strings can be [joined][join] into one. + +[char-docs]: https://docs.julialang.org/en/v1/manual/strings/#man-characters +[isspace]: https://docs.julialang.org/en/v1/base/strings/#Base.Unicode.isspace +[isdigit]: https://docs.julialang.org/en/v1/base/strings/#Base.Unicode.isdigit +[lowercase]: https://docs.julialang.org/en/v1/base/strings/#Base.Unicode.lowercase +[isuppercase]: https://docs.julialang.org/en/v1/base/strings/#Base.Unicode.isuppercase +[join]: https://docs.julialang.org/en/v1/base/strings/#Base.join diff --git a/exercises/concept/squeaky-clean/.docs/instructions.md b/exercises/concept/squeaky-clean/.docs/instructions.md new file mode 100644 index 00000000..0fec844d --- /dev/null +++ b/exercises/concept/squeaky-clean/.docs/instructions.md @@ -0,0 +1,60 @@ +# Instructions + +In this exercise you will implement a partial set of utility routines to help a developer clean up identifier names. + +In the 6 tasks you will gradually build up the functions `transform` to convert single characters and `clean` to convert strings. + +A valid identifier comprises zero or more letters, underscores, hyphens, question marks and emojis. + +If an empty string is passed to the `clean` function, an empty string should be returned. + +## 1. Replace any hyphens encountered with underscores + +Implement the `transform` function to replace any hyphens with underscores. + +```julia +transform('-') # => "_" +``` + +## 2. Remove all whitespace + +Remove all whitespace characters. +This will include leading and trailing whitespace. + +```julia +transform(' ') # => "" +``` + +## 3. Convert camelCase to kebab-case + +Modify the `transform` function to convert camelCase to kebab-case + +```julia +transform('D') # => "-d" +``` + +## 4. Omit characters that are digits + +Modify the `transform` function to omit any characters that are numeric. + +```julia +transform('7') # => "" +``` + +## 5. Replace Greek lower case letters with question marks + +Modify the `transform` function to replace any Greek letters in the range 'α' to 'ω'. + +```julia +transform('β') # => "?" +``` + +## 6. Combine these operations to operate on a string + +Implement the `clean` function to apply these operations to an entire string. + +Characters which fall outside the rules should pass through unchanged. + +```julia +clean(" a2b Cd-ω😀 ") # => "ab-cd_?😀" +``` diff --git a/exercises/concept/squeaky-clean/.docs/introduction.md b/exercises/concept/squeaky-clean/.docs/introduction.md new file mode 100644 index 00000000..f3dadca7 --- /dev/null +++ b/exercises/concept/squeaky-clean/.docs/introduction.md @@ -0,0 +1,3 @@ +# Introduction + +_Left blank for now. Contents of `concepts/chars/introduction.md` to be copied here when finalized._ \ No newline at end of file diff --git a/exercises/concept/squeaky-clean/.meta/config.json b/exercises/concept/squeaky-clean/.meta/config.json new file mode 100644 index 00000000..c14919e0 --- /dev/null +++ b/exercises/concept/squeaky-clean/.meta/config.json @@ -0,0 +1,20 @@ +{ + "authors": [ + "colinleach" + ], + "files": { + "solution": [ + "squeaky-clean.jl" + ], + "test": [ + "runtests.jl" + ], + "exemplar": [ + ".meta/exemplar.jl" + ] + }, + "forked_from": [ + "fsharp/squeaky-clean" + ], + "blurb": "Learn about characters by cleaning strings." +} diff --git a/exercises/concept/squeaky-clean/.meta/exemplar.jl b/exercises/concept/squeaky-clean/.meta/exemplar.jl new file mode 100644 index 00000000..38b76287 --- /dev/null +++ b/exercises/concept/squeaky-clean/.meta/exemplar.jl @@ -0,0 +1,16 @@ +function transform(ch) + if ch == '-' + "_" + elseif 'α' ≤ ch ≤ 'ω' + "?" + elseif isspace(ch) || isdigit(ch) + "" + elseif isuppercase(ch) + "-$(lowercase(ch))" + else + string(ch) + end +end + +# The default delimiter is "", so it is only included below for documentation +clean(str) = join([transform(ch) for ch in str], "") diff --git a/exercises/concept/squeaky-clean/runtests.jl b/exercises/concept/squeaky-clean/runtests.jl new file mode 100644 index 00000000..fb4aab13 --- /dev/null +++ b/exercises/concept/squeaky-clean/runtests.jl @@ -0,0 +1,34 @@ +using Test + +include("squeaky-clean.jl") + +@testset verbose = true "tests" begin + @testset "1. Hyphens" begin + @test transform('a') == "a" + @test transform('-') == "_" + end + + @testset "2. Whitespace" begin + @test transform(' ') == "" + end + + @testset "3. camelCase" begin + @test transform('Γ') == "-γ" + end + + @testset "4. digits" begin + @test transform('4') == "" + end + + @testset "5. Greek lowercase" begin + @test transform('ω') == "?" + end + + @testset "6. Combine in string" begin + @test clean("") == "" + @test clean("àḃç") == "àḃç" + @test clean("my id") == "myid" + @test clean(" my id ") == "myid" + @test clean("9 cAbcĐ😀ω") == "c-abc-đ😀?" + end +end diff --git a/exercises/concept/squeaky-clean/squeaky-clean.jl b/exercises/concept/squeaky-clean/squeaky-clean.jl new file mode 100644 index 00000000..2c60510e --- /dev/null +++ b/exercises/concept/squeaky-clean/squeaky-clean.jl @@ -0,0 +1,7 @@ +function transform(ch) + +end + +function clean(str) + +end