Render a calendar - 14.4 - comment on solution

#1

This particular line and the comment, does the comment tell what the code is actually doing?

// If times are equal, an endpoint that starts an interval comes first.
return isStart && !e.isStart ? -1 : !isStart && e.isStart ? 1 : 0;

If we are to return an endpoint that starts an interval comes first, then “isStart && !e.isStart ?” should be 1 not -1, isn’t it, if this object (isStart) is true.

To what I understand, based on the comment that would be
return isStart && !e.isStart ? 1 : !isStart && e.isStart ? -1 : 0;

0 Likes

#2

Hi @Artem,

The comment does state what we exactly we want to do. I think it would be good for you to review Java how comparator works. Also, you shall try this on the new EPI Judge framework as you can run the program by yourself.

0 Likes

#3

Actually it’s clear now. -1 in “isStart && !e.isStart” means that “this” object is smaller so sort it first in (smallest to biggest). Thanks for quick reply!

1 Like