Skip to content

Instantly share code, notes, and snippets.

@PEZ
Last active May 27, 2024 01:33
Show Gist options
  • Save PEZ/bdbcf005bcae10b15531ebe3a7d0be9c to your computer and use it in GitHub Desktop.
Save PEZ/bdbcf005bcae10b15531ebe3a7d0be9c to your computer and use it in GitHub Desktop.
Get the Caps – Rich 4Clojure Problem 29 – See: https://github.com/PEZ/rich4clojure
(ns rich4clojure.easy.problem-029
(:require [hyperfiddle.rcf :refer [tests]]))
;; = Get the Caps =
;; By 4Clojure user: dbyrne
;; Difficulty: Easy
;; Tags: [strings]
;;
;; Write a function which takes a string and returns a new
;; string containing only the capital letters.
(def __ :tests-will-fail)
(comment
)
(tests
(__ "HeLlO, WoRlD!") := "HLOWRD"
(__ "nothing") :=
(__ "$#A(*&987Zf") := "AZ")
;; To participate, fork:
;; https://github.com/PEZ/rich4clojure
;; Post your solution below, please!
@szalai1
Copy link

szalai1 commented Aug 23, 2021

(fn [s] (apply str (filter #(Character/isUpperCase %) s)))

@StanTheBear
Copy link

#(apply
str (re-seq #"[A-Z]" %)))

Had to edit (tests 2 to
(__ "nothing") := "", cant think of any way to return no action for "" or nil?

Copy link

ghost commented Nov 2, 2023

(def __ #(loop [el (seq %)
                res ""]
           (if (nil? el)
             (str res)
             (recur (next el)
                    (if (Character/isUpperCase (first el))
                      (str res (first el))
                      res)))))

@jsebdev
Copy link

jsebdev commented May 27, 2024

(def __ (fn [s]
          (->> s
               (filter (fn [c] (Character/isUpperCase c)))
               (apply str)
               )))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment