JavaScript syntax: bucketing based on days (today, yesterday and past) I am trying to create three buckets of objects. Today, yesterday and past. I am wondering can the following be done in a more concise way in pure JavaScript without any libraries?
const [todayBucket, yesterdayBucket] = [0, 1].map(offset =&gt;
  recordings.filter(({ createdOn }) =&gt;
    moment(createdOn).isSame(moment().add(-offset), 'day'),
  ),
);
const pastBucket = recordings.filter(
  recording =&gt; ![...todayBucket, ...yesterdayBucket].includes(recording),
);
Doing it without an additional library you could try a custom function that does the same thing
function isSame(a,offset) {
    const b = new Date();
    b.setDate(b.getDate() - offset); 
    return a === b
}

const [todayBucket, yesterdayBucket] = [0, 1].map(offset =&gt;
  recordings.filter(({ createdOn }) =&gt;
    isSame(createdOn,offset),
  ),
);
const pastBucket = recordings.filter(
  recording =&gt; ![...todayBucket, ...yesterdayBucket].includes(recording),
);