export function renderItems(categories, items) { const arrayCategories = categories; const arrayItems = items; let html = ''; arrayCategories.forEach(category => { html += `

${category.title}

`; arrayItems.forEach(item => { if (item.category.toLowerCase() === category.title.toLowerCase()) { html += `
#
${diffDates(new Date(), new Date(item.date))}
${item.count} шт.
Цена за 1 шт.
${item.price.toFixed(2)}₽
`; } }) }); return html; } function diffDates(firstDate, secondDate) { let diff = Math.floor((firstDate - secondDate) / (60 * 60 * 24 * 1000)); if (diff <= 0) { return 'добавлено сегодня'; } return diff + ' дней назад'; }