我在显示一年中的正确月份时遇到问题。问题是几个月不互相跟进。我似乎无法正确理解算法。
我现在遇到的问题是,这些月份不能正确地相互跟进。不应使用“Jan-Feb-Mar-Dec”,而应为“Dec-Jan-Feb-Mar”:
这是我在这一点上的算法。当月份在不同年份重叠时,我无法理解如何按正确的顺序排列月份。新年的月份是数组开始的月份:
visibleMonths() {
let oldestMonth = 0;
this.months.forEach(month => {
if (month.visible && month.value > oldestMonth)
oldestMonth = month.value;
});
if (oldestMonth + 4 > 11) {
let visibleMonths = [];
// ORDER THE MONTHS
} else {
return this.months.filter(month => month.visible === true);
}
}
months: [
{ name: "Jan", value: 0, active: false, visible: false },
{ name: "Feb", value: 1, active: false, visible: false },
{ name: "Mar", value: 2, active: false, visible: false },
{ name: "Apr", value: 3, active: false, visible: false },
{ name: "Mei", value: 4, active: false, visible: false },
{ name: "Jun", value: 5, active: false, visible: false },
{ name: "jul", value: 6, active: false, visible: false },
{ name: "Aug", value: 7, active: false, visible: false },
{ name: "Sep", value: 8, active: false, visible: false },
{ name: "Okt", value: 9, active: false, visible: false },
{ name: "Nov", value: 10, active: false, visible: false },
{ name: "Dec", value: 11, active: false, visible: false }
],
慕娘9325324
相关分类