Сообщество IT-специалистов
Ответы на любые вопросы об IT
Профессиональное развитие в IT
Удаленная работа для IT-специалистов
private function getMaxQuality(array $photo): array { $sizes = $photo['sizes']; unset($photo['sizes']); $arr = []; foreach ($sizes as $k => $size) { $arr[] = $size['type']; } array_multisort($arr, SORT_DESC, $sizes); $photo['url'] = $sizes[0]['url']; return $photo; }
def get_largest(size_dict): weight = {'o': 0, 'p': 0, 'q': 0, 'r': 0, 's': 0, 'm': 10, 'x': 20, 'y': 30, 'z': 40, 'w': 50} size_dict['type'] = weight[size_dict['type']] return size_dict['type'] max_size_url = max(sizes, key=get_largest)['url']
size_dict['type'] = weight[size_dict['type']]
function get_weight($item) { static $weight_table = ['o' => 0, 'p' => 0, 'q' => 0, 'r' => 0, 's' => 0, 'm' => 10, 'x' => 20, 'y' => 30, 'z' => 40, 'w' => 50]; return $weight_table[$item->type]; } function get_biggest_size($sizes) { $weights = array_map('get_weight', $sizes); $max_weight = max($weights); $max_weight_index = array_search($max_weight, $weights); return $sizes[$max_weight_index]; } $max_size_url = get_biggest_size($sizes)->src;