A Common-Sense Guide to Data Structures and Algorithms, Second Edition: Verbose condition in greatest product (page 469)

A Common-Sense Guide to Data Structures and Algorithms, Second Edition by Jay Wengrow @jaywengrow

Hi,

in the book version, in the page 469 there is the following if condition:

if number <= lowest_number

elsif number > lowest_number && 
      number < second_to_lowest_number

end

I think that in the else condition, the one on the left of the AND operator is verbose, because if the number is < of second_to_last_number, is becuse is not <= of lowest_number. So there is not ovelapping cases. Therefore:

if number <= lowest_number 

elsif number < second_to_lowest_number 

end

Please, con you tell me, what do you think? Manu thanks!

You have a good point! I think you are correct and that extra clause isn’t necessary in the end.

Thanks!
Jay

1 Like