// Сначала, как обычно сортируем по статусу
if (a.status > b.status) return 1;
if (a.status < b.status) return -1;
// Потом, если статусы равны, - по дате
if (a.date > b.date) return 1;
if (a.date < b.date) return -1;
return 0;
arr.sort((a,b) => {
if (a.status === b.status) {
if (a.date === b.date) return 0;
return a.date > b.date ? 1 : -1;
}
return a.status > b.status ? 1 : -1;
})
class GeoIp
{
private \SxGeo $sxGeo;
public function __construct()
{
$this->sxGeo = new \SxGeo(Storage::disk('local')->path('sxgeo/SxGeo.dat'));
}
public function getDetectedCountry($ip = null)
{
if (!$ip) {
$ip = real_ip();
}
$countryCode = strtolower($this->sxGeo->getCountry($ip)) ?: 'ru';
return Country::find($countryCode);
}
}
Какие конструкции использовать, что бы изменить порядок в массиве
<div id="open-modal-btn" class="banner-text-btn">
<div><button>Оставить заявку</button></div>
</div>
<?php require "button.php"?>
<script src="js/modal-application.js"></script>
<div class="banner-text-btn">
<div><button id="open-modal-btn">Оставить заявку</button></div>
<?php require "button.php"?>
<script src="js/modal-application.js"></script>
</div>
async function getData() {
const url = document
.querySelector(`[data-id="${window.location.hash.substring(1)}"]`)
?.dataset.url; // Вот здесь этот спасительный знак =)
if (!url) return;
const response = await fetch(url);
const data = await response.json();
return data;
}
{ name: 'Вася', age: 25 }
function getAvarageAge(arr) {
return arr.reduce((sum, item) => sum + item.age, 0) / arr.length;
}
let vasya = { name: 'Вася', age: 25 };
let petya = { name: 'Петя', age: 30 };
let masha = { name: 'Маша', age: 29 };
let arr = [vasya, petya, masha];
console.log(getAvarageAge(arr)); // 28