Tallest/Widest product image/ largest integer in an array

So I’m trying to find an image with the largest height value in product.media.

Something like this is like one line in javascript, but I’m a bit stumped on how to go about it in liquid.

Has anyone written something like this before?

This should work:

{%- liquid assign largestHeight = 0
for media in product.media
  if media.height > largestHeight
    assign largestHeight = media.height
  endif
endfor 

for media in product.media
  if media.height == largestHeight
    assign largestImage = media
    break
  endif
endfor -%}