Skip to content

Instantly share code, notes, and snippets.

@qoelet
Created March 9, 2020 13:22
Show Gist options
  • Save qoelet/24f1b57ebd075658fe15714b20694e5e to your computer and use it in GitHub Desktop.
Save qoelet/24f1b57ebd075658fe15714b20694e5e to your computer and use it in GitHub Desktop.
PF.tv challenge: remove-last-vowels
(require '[clojure.string :as string])
(defn is-vowel? [character]
(contains? #{\a \e \i \o \u} character))
(defn remove-last-vowel [word]
(defn go [xs flag]
(cond
(or (empty? xs) flag)
xs
(is-vowel? (first xs))
(cons "" (go (rest xs) true))
:else
(cons (first xs) (go (rest xs) false))))
(string/join "" (reverse (go ((comp reverse seq) word) false))))
(defn remove-last-vowels [sentence]
(let [words (string/split sentence #" ")
words-without-last-vowels (map (comp not-empty remove-last-vowel) words)]
(string/join " " (remove nil? words-without-last-vowels))))
(comment
test.clj
(ns remove-vowels.core-test
(:use midje.sweet)
(:require [remove-vowels.core :refer :all]))
(facts "remove-last-vowel"
(fact "removes the last vowel"
(remove-last-vowel "there!") => "ther!"))
(facts "remove-last-vowels"
(fact "test 1"
(remove-last-vowels "Hi, there!") => "H, ther!")
(fact "test 2"
(remove-last-vowels "This is not a test.") => "Ths s nt tst.")
(fact "test 3"
(remove-last-vowels "Hippopotamus") => "Hippopotams"))
$ lein midje
All checks (4) succeeded.
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment