-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor is-pangram function for improved performance
- Loading branch information
1 parent
81b7f8d
commit 8281564
Showing
1 changed file
with
10 additions
and
11 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,12 @@ | ||
(ns otus-02.homework.pangram | ||
(:require [clojure.string :as string] | ||
[clojure.set :as set])) | ||
|
||
(def alphabet-set (set "abcdefghijklmnopqrstuvwxyz")) | ||
(ns otus-02.homework.pangram) | ||
|
||
(defn is-pangram [^String input] | ||
(let [normalized-chars (-> input | ||
string/lower-case | ||
(string/replace #"[^a-z]" "") | ||
set)] | ||
(set/subset? alphabet-set normalized-chars))) | ||
|
||
(loop [chars input | ||
found-letters #{}] | ||
(if (or (empty? chars) (= 26 (count found-letters))) | ||
This comment has been minimized.
Sorry, something went wrong. |
||
(= 26 (count found-letters)) | ||
(let [current-char (Character/toLowerCase (first chars))] | ||
(if (and (>= (int current-char) (int \a)) | ||
(<= (int current-char) (int \z))) | ||
This comment has been minimized.
Sorry, something went wrong.
Ivana-
|
||
(recur (rest chars) (conj found-letters current-char)) | ||
(recur (rest chars) found-letters)))))) | ||
This comment has been minimized.
Sorry, something went wrong. |
(or (= 26 (count found-letters)) .....
without duplicates :)