Y
Hacker News
new
|
ask
|
show
|
jobs
by
onli
378 days ago
Yes. And then clamp(0..) removes the -1, maps it to a 0. Why you'd want that? No idea.
1 comments
mdoliwa
378 days ago
so this just says if we have free places or not? students.size < maximum_number_of_students
link
jackbracken
378 days ago
It gives the number of free places, hinted by the method name `available_places`
Needlessly ugly way to write it imo though
link
onli
378 days ago
But it doesn't. The code will only ever output 0 or 1. With a regular <=> operator at least.
link
mdoliwa
378 days ago
yeah, so basically 1 we have available places, 0 we do not.
link
vidarh
378 days ago
I think it probably made sense to the author because they've used all three (-1,0,1) for other examples, and would've been fine until separated out to a method reused to show the actual number.
I think they tried to be a bit too clever, basically.
link