-
Notifications
You must be signed in to change notification settings - Fork 8
Домашнее задание 2: палиндром #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,15 @@ | ||
| (ns otus-02.homework.palindrome) | ||
| (ns otus-02.homework.palindrome | ||
| (:require [clojure.string :as cs])) | ||
|
|
||
| (defn- bad-char? [c] | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. в принципе тот же совет что и выше про алиасы, лучше называть переменные и аргументы какими то осмысленными словами. через месяц или два становится очень трудно понять что значит буква |
||
| (boolean (some #{\space \? \,} [c]))) | ||
|
|
||
| (defn is-palindrome [test-string]) | ||
| (defn- bad-char-to-nil [c] | ||
| (when-not (bad-char? c) | ||
| c)) | ||
| (defn- rm-bad-chars [s] | ||
| (apply str (map bad-char-to-nil s))) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. хорошее решение через map |
||
| (defn is-palindrome [test-string] | ||
| (let [s (cs/lower-case (rm-bad-chars test-string)) | ||
| rs (cs/reverse s)] | ||
| (= s rs))) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
это не ошибка, а скорее совет на будущее - одно или дву буквенные алиасы не рекомендуется использовать так как в будущем будет тяжело понять что это значит
в данном случае можно использовать string в качестве алиаса