Calculating whether it's a leap year isn't a straightforward as you might think! Here's how leap years are calculated, as described on Wikipedia:
...
For further actions, you may consider blocking this person and/or reporting abuse
You can do a ternary condition to minimize lines, like this:
I don't think this will evaluate correctly. Also, long one-liners can feel efficient but they're often pretty hard for others to understand.
Really, for those who are not used to it, it is difficult to understand. When I started working with tender conditions I thought "This is very strange!", but I forced myself to learn (even to leave the comfort zone) and now it has become very simple. It's a matter of habit, and believe me, it works perfectly!
What I'm saying is that your function literally doesn't work correctly.
That's incorrect.
Oh, sorry, you're right! I forget something.
Try again with my changes.
In this case, why do you even need the ternary?
true
will always evaluate totrue
.In other words, this:
is the exact same thing as this:
Perfect!!
I totally agree with you! 👏👏👏👏👏👏
Very clean. But do the 3 parts in the opposite order.
Assuming you get years randomly, most will be not %4, so handle those first.
Similarly, most %4 years will be not %100, so those are next.
just in case the price of 2 extra "if"s is going to break you.
I love these short questions and simple explanations! Please do more of these 😁
Wow this is straight forward. Thanks for sharing.
Clever, but too obscure to save 2 lines of code.
Moreover, using date libs is not cricket. If you have those, I presume you can just ask
Date.isLeapYear(year)
(with some syntax or other)
Oh great :o