document.addEventListener('DOMContentLoaded', function() {
let numbers = [
'+38 (095) 123 45 67',
'+38 (096) 123 45 67',
'+38 (097) 123 45 67',
'+38 (098) 123 45 67',
'+38 (099) 123 45 67',
];
function getNumber(numbers){
numbers.push(numbers.shift());
return numbers[0];
}
function setNumber(number){
let link = document.getElementById('phone');
link.innerText = number;
link.setAttribute('href', 'tel:' + number);
}
function update(){
setNumber(getNumber(numbers));
}
update();
setInterval(update, 2000);
});
Array.isArray
и ещё сразу проверять идентичность длины и её наличие. const f = (a, b) => Array.isArray(a) && Array.isArray(b) && a.length === b.length && a.length > 0 ?
a.every((item, index) => f(item, b[index])) :
a === b;
console.log(f([0, 1, [3]], [0, 1, [3]]))
function increaseSalary() {
return new Promise((resolve, reject) => {
let minSalaryEmployee = Promise.resolve().then((employeeData) => {
return { };
});
minSalaryEmployee
.then((data) => {
let newSalary = Promise.reject();
newSalary
.then((newData) => {
resolve(`Ok`);
})
.catch((e) => {
reject(`Error`)
});
})
.catch(reject);
});
}
increaseSalary()
.then(console.log)
.catch(console.error);
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link id="time-theme" rel="stylesheet" href="">
<script src="./time-theme.js"></script>
</head>
<body>
</body>
</html>
let timeRanges = new Set([
{range: {from: `24`, to: `4`}, name:`night`, href:`./dark-theme.css`},
{range: {from: `4`, to: `12`}, name: `morning`, href:`./light-theme.css`},
{range: {from: `12`, to: `17`}, name: `day`, href:`./light-theme.css`},
{range: {from: `17`, to: `24`}, name: `evening`, href:`./dark-theme.css`},
]);
const changeTheme = timeRanges => {
let currentHour = new Date().getHours();
for(let {range, href, name} of timeRanges){
if(currentHour >= range.from && currentHour <= range.to){
Object.assign(document.querySelector(`link#time-theme`), { href });
break;
}
}
}
changeTheme(timeRanges);