Skip to content
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

Add leap year task #402

Merged
merged 8 commits into from Jul 9, 2020
Merged

Add leap year task #402

merged 8 commits into from Jul 9, 2020

Conversation

solar05
Copy link
Member

@solar05 solar05 commented Jul 4, 2020

No description provided.

@solar05
Copy link
Member Author

solar05 commented Jul 4, 2020

Issue #403

src/battle_asserts/issues/leap_year.clj Outdated Show resolved Hide resolved
src/battle_asserts/issues/leap_year.clj Show resolved Hide resolved
src/battle_asserts/issues/leap_year.clj Show resolved Hide resolved
@solar05 solar05 requested a review from vtm9 July 5, 2020 12:12
:arguments [2020]}])

(defn solution [year]
(if (and (zero? (mod year 4)) (not (and (zero? (mod year 100)) (not= (mod year 400) 0)))) true false))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

предлагаю убрать if, так как внутри итак булево выражение и не нужно его явно отображать. А для явности выражения использовать let чтобы дать поясняющие имена составляющим выражение частям.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Я что-то слишком сильно зациклился на решении первоисточника)
Такой вариант лучше будет?
(defn solution [year] (cond (zero? (mod year 400)) true (zero? (mod year 100)) false (zero? (mod year 4)) true :default false))

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А,черт.форматирование сломалось, сейчас комитну тогда

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(zero? (mod year 400)) уже булево выражение, его можно ни в if ни в cond не писать.
предлагаю что-то вроде такого

(defn solution [year]                                                                                                                                                     
  (letfn [(divisible? [a b]                                                                                                                                               
            (zero? (mod a b)))]                                                                                                                                           
    (and (divisible? year 4) (not (divisible? year 400))))) 

@imamatory imamatory self-requested a review July 6, 2020 20:11
@vtm9 vtm9 merged commit eb38333 into hexlet-codebattle:master Jul 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants