获取每个用户满足条件的最大连续天数可以通过以下步骤实现:
以下是一个示例的JavaScript代码实现:
function getMaxConsecutiveDays(userDates, condition) {
userDates.sort(); // 按日期升序排序
let currentConsecutiveDays = 0;
let maxConsecutiveDays = 0;
for (let i = 0; i < userDates.length; i++) {
if (userDates[i] === condition) {
currentConsecutiveDays++;
} else {
currentConsecutiveDays = 0;
}
if (currentConsecutiveDays > maxConsecutiveDays) {
maxConsecutiveDays = currentConsecutiveDays;
}
}
return maxConsecutiveDays;
}
// 示例数据
const user1Dates = ['2022-01-01', '2022-01-02', '2022-01-03', '2022-01-05', '2022-01-06'];
const user2Dates = ['2022-01-01', '2022-01-02', '2022-01-03', '2022-01-04', '2022-01-05'];
const condition = '2022-01-03';
const user1MaxConsecutiveDays = getMaxConsecutiveDays(user1Dates, condition);
const user2MaxConsecutiveDays = getMaxConsecutiveDays(user2Dates, condition);
console.log(`User 1的满足条件的最大连续天数:${user1MaxConsecutiveDays}`);
console.log(`User 2的满足条件的最大连续天数:${user2MaxConsecutiveDays}`);
请注意,以上示例代码仅为演示如何获取每个用户满足条件的最大连续天数,并不包含具体的腾讯云产品和链接地址。具体的产品和链接地址需要根据实际需求和使用情况进行选择和提供。
领取专属 10元无门槛券
手把手带您无忧上云