JavaScript
- 4 ответа
- 0 вопросов
1
Вклад в тег
const filteredArray = transactions.filter((item) => {
const dataTokens = item.date.split('.');
const date = new Date(+dataTokens[2], +dataTokens[1] - 1, +dataTokens[0]);
return date.getDate() >= 24 && date.getDate() <= 25;
});
console.log(filteredArray);
let currentMonth = 0;
let isFirstRun = true;
let bufferSumInMonth = 0;
const pricesArray = [];
for (let i = 0; i < transactions.length; i++) {
const currentItem = transactions[i];
const dataTokens = currentItem.date.split('.');
const date = new Date(+dataTokens[2], +dataTokens[1] - 1, +dataTokens[0]);
if (isFirstRun) { currentMonth = date.getMonth(); isFirstRun = false; }
if (currentMonth === date.getMonth() && (date.getDate() >= 24 && date.getDate() <= 25)) {
bufferSumInMonth += parseInt(currentItem.price, 10);
} else if (currentMonth !== date.getMonth() || i === transactions.length - 1) {
console.log(bufferSumInMonth);
pricesArray.push({ sum: bufferSumInMonth, month: date.getMonth() });
bufferSumInMonth = 0;
}
currentMonth = date.getMonth();
}
console.log(pricesArray);