Skip to content
This repository has been archived by the owner on May 30, 2023. It is now read-only.

Commit

Permalink
Add acronym exercise (#112)
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikSchierboom authored May 6, 2023
1 parent f4527a8 commit 747a087
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 0 deletions.
13 changes: 13 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,19 @@
"difficulty": 5,
"topics": null
},
{
"slug": "acronym",
"name": "Acronym",
"uuid": "e6147a0d-3000-4b3c-9a60-3f8800730691",
"practices": [
"strings"
],
"prerequisites": [
"strings",
"booleans"
],
"difficulty": 2
},
{
"slug": "accumulate",
"name": "Accumulate",
Expand Down
17 changes: 17 additions & 0 deletions exercises/practice/acronym/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Instructions

Convert a phrase to its acronym.

Techies love their TLA (Three Letter Acronyms)!

Help generate some jargon by writing a program that converts a long name like Portable Network Graphics to its acronym (PNG).

Punctuation is handled as follows: hyphens are word separators (like whitespace); all other punctuation can be removed from the input.

For example:

|Input|Output|
|-|-|
|As Soon As Possible|ASAP|
|Liquid-crystal display|LCD|
|Thank George It's Friday!|TGIF|
19 changes: 19 additions & 0 deletions exercises/practice/acronym/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"authors": [
"ErikSchierboom"
],
"files": {
"solution": [
"src/acronym.cljs"
],
"test": [
"test/acronym_test.cljs"
],
"example": [
".meta/src/example.cljs"
]
},
"blurb": "Convert a long phrase to its acronym.",
"source": "Julien Vanier",
"source_url": "https://github.com/monkbroc"
}
8 changes: 8 additions & 0 deletions exercises/practice/acronym/.meta/src/example.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(ns acronym
(:require [clojure.string :as str]))

(defn acronym [text]
(->> (re-seq #"[A-Z]+[a-z]*|[a-z]+" text)
(map first)
(apply str)
str/upper-case))
30 changes: 30 additions & 0 deletions exercises/practice/acronym/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# This is an auto-generated file. Regular comments will be removed when this
# file is regenerated. Regenerating will not touch any manually added keys,
# so comments can be added in a "comment" key.

[1e22cceb-c5e4-4562-9afe-aef07ad1eaf4]
description = "basic"

[79ae3889-a5c0-4b01-baf0-232d31180c08]
description = "lowercase words"

[ec7000a7-3931-4a17-890e-33ca2073a548]
description = "punctuation"

[32dd261c-0c92-469a-9c5c-b192e94a63b0]
description = "all caps word"

[ae2ac9fa-a606-4d05-8244-3bcc4659c1d4]
description = "punctuation without whitespace"

[0e4b1e7c-1a6d-48fb-81a7-bf65eb9e69f9]
description = "very long abbreviation"

[6a078f49-c68d-4b7b-89af-33a1a98c28cc]
description = "consecutive delimiters"

[5118b4b1-4572-434c-8d57-5b762e57973e]
description = "apostrophes"

[adc12eab-ec2d-414f-b48c-66a4fc06cdef]
description = "underscore emphasis"
10 changes: 10 additions & 0 deletions exercises/practice/acronym/deps.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{:deps
{org.clojure/clojure {:mvn/version "1.10.1"}
org.clojure/clojurescript {:mvn/version "1.10.773"}}

:aliases
{:test
{:extra-paths ["test"]
:extra-deps
{olical/cljs-test-runner {:mvn/version "3.8.0"}}
:main-opts ["-m" "cljs-test-runner.main"]}}}
5 changes: 5 additions & 0 deletions exercises/practice/acronym/src/acronym.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(ns acronym)

(defn acronym [] ;; <- arglist goes here
;; your code goes here
)
24 changes: 24 additions & 0 deletions exercises/practice/acronym/test/acronym_test.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
(ns acronym-test
(:require [clojure.test :refer [deftest is]]
acronym))

(deftest test-acronym-empty-string
(is (= "" (acronym/acronym ""))))

(deftest test-acronym-png
(is (= "PNG" (acronym/acronym "Portable Network Graphics"))))

(deftest test-acronym-ror
(is (= "ROR" (acronym/acronym "Ruby on Rails"))))

(deftest test-acronym-html
(is (= "HTML" (acronym/acronym "HyperText Markup Language"))))

(deftest test-acronym-fifo
(is (= "FIFO" (acronym/acronym "First In, First Out"))))

(deftest test-acronym-php
(is (= "PHP" (acronym/acronym "PHP: Hypertext Preprocessor"))))

(deftest test-acronym-cmos
(is (= "CMOS" (acronym/acronym "Complementary metal-oxide semiconductor"))))

0 comments on commit 747a087

Please sign in to comment.