Last active
May 17, 2023 00:43
-
-
Save chase-lambert/1bfaf57cc9fb61a61667cd9021279754 to your computer and use it in GitHub Desktop.
rendezvous with cassidoo challenge: 22.10.10
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
(ns truncate | |
(:require [clojure.test :refer [deftest is])) | |
(defn truncate [s n] | |
(let [tokens (re-seq #"\W+|_|[a-zA-Z]+" s) | |
word? #(re-find #"\w+" %) | |
truncate-w (fn [token] | |
(if (and (word? token) | |
(> (count token) n)) | |
(subs token 0 n) | |
token)) | |
truncated (map truncate-w tokens)] | |
(apply str truncated))) | |
(deftest truncate-test | |
(let [n 3] | |
(is (= "nev gon giv you up" (truncate "never gonna give you up" n))) | |
(is (= "*hel* dar, my ~old_fri" (truncate "*hello* darkness, my ~old_friend" n))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment