stuck in the loops

Some Linqy pseudocode on how I’d approach it:

destination = storehouses
              .OrderBy( storehouse.distance )
              .FirstOrDefault( storehouse.contains(item) )

Although you’re probably better off doing a single-pass iteration:

SomeType destination
foreach storehouse in storehouses
    if ( storehouse.contains(item) )
        if ( destination is null || storehouse.distance < destination.distance )
            destination = storehouse

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top