Avatar of murdho

murdho's solution

to Isogram in the Clojure Track

Published at Jul 13 2018 · 0 comments
Instructions
Test suite
Solution

Determine if a word or phrase is an isogram.

An isogram (also known as a "nonpattern word") is a word or phrase without a repeating letter, however spaces and hyphens are allowed to appear multiple times.

Examples of isograms:

  • lumberjacks
  • background
  • downstream
  • six-year-old

The word isograms, however, is not an isogram, because the s repeats.

Source

Wikipedia https://en.wikipedia.org/wiki/Isogram

Submitting Incomplete Solutions

It's possible to submit an incomplete solution so you can see how others have completed the exercise.

isogram_test.clj

(ns isogram-test
  (:require [clojure.test :refer [deftest is]]
            isogram))

(deftest test-isograms
  (is (isogram/isogram? "duplicates"))
  (is (isogram/isogram? "subdermatoglyphic"))
  (is (isogram/isogram? "thumbscrew-japingly"))
  (is (isogram/isogram? "Hjelmqvist-Gryb-Zock-Pfund-Wax"))
  (is (isogram/isogram? "Heizölrückstoßabdämpfung"))
  (is (isogram/isogram? "Emily Jung Schwartzkopf")))

(deftest test-non-isograms
  (is (not (isogram/isogram? "eleven")))
  (is (not (isogram/isogram? "Alphabet")))
  (is (not (isogram/isogram? "the quick brown fox")))
  (is (not (isogram/isogram? "éléphant"))))
(ns isogram)

(defn isogram? [s]
  (->> s
       (clojure.string/lower-case)
       (filter #(Character/isLetter %))
       (apply distinct?)))

Community comments

Find this solution interesting? Ask the author a question to learn more.

What can you learn from this solution?

A huge amount can be learned from reading other people’s code. This is why we wanted to give exercism users the option of making their solutions public.

Here are some questions to help you reflect on this solution and learn the most from it.

  • What compromises have been made?
  • Are there new concepts here that you could read more about to improve your understanding?