function setArrayAtPath(obj, path) {
return path.reduce((acc, val, i) => {
acc[val] ??= (i === path.length - 1) ? [] : {};
return acc[val];
}, obj);
}
const result = links.reduce((acc, val) => {
const fullPath = val.url.split('/');
const path = fullPath.slice(0, -1);
const dir = setArrayAtPath(acc, path);
let insertIdx = dir.findIndex(o => o.timestamp > val.timestamp);
insertIdx = insertIdx === -1 ? dir.length : Math.max(0, insertIdx - 1);
dir.splice(insertIdx, 0, { ...val });
return acc;
}, {});
console.log(result);
.swiper {
width: 100%;
height: 100%;
position: initial; / * <-- убрать */
}
header{
display: block;
padding: 10px;
position: fixed;
/* ........... */
z-index: 1; / * <-- сделать больше */
const uniqueCellsCount = json.data.reduce((acc, c) => acc.add(c.cell), new Set()).size;
const watch = document.querySelector("#watch");
let milliseconds = 0;
let timer;
function millisToHuman(milliseconds) {
return new Date(milliseconds).toISOString().slice(11, 22);
}
const startWatch = () => {
watch.classList.remove("paused");
clearInterval(timer);
timer = setInterval(() => {
milliseconds += 10;
const timeStr = millisToHuman(milliseconds);
result.innerHTML = timeStr;
watch.innerHTML = timeStr;
}, 10);
};
const pauseWatch = () => {
watch.classList.add("paused");
clearInterval(timer);
};
const resetWatch = () => {
watch.classList.remove("paused");
clearInterval(timer);
milliseconds = 0;
watch.innerHTML = "00:00:00:00";
result.innerHTML = "00:00:00:00";
};
document.addEventListener("click", (e) => {
const element = e.target;
if (element.id === "start") startWatch();
if (element.id === "pause") pauseWatch();
if (element.id === "reset") resetWatch();
});
function newLapTime() {
const lap = document.querySelector('.lapContainer');
lap.innerHTML += `<br/><div> ${millisToHuman(milliseconds)} </div>`;
milliseconds = 0;
}
const throttledAddComment = throttle(addCommentFn, 5000);
sendButton.click((e) =>{
e.preventDefault();
throttledAddComment();
});
function func(data) {
if (data instanceof Event) {
var id = data.target.id;
} else {
var id = data;
}
}
detail
в объекте событияfunction func(event) {
const id = event.detail ? event.detail.id : event.target.id;
}
domElement.dispatchEvent(new CustomEvent('event-name', { detail: { id: 'id-42' } }));