Store logs by timestamp and retrieve them by year, month, day, hour, minute or second

mediumAbout 30 minutesUpdated CodingProdesignstringsdatesbinary-search
Not solved

Share this question

Problem

Logs, analytics events and audit trails are usually queried by time range at a chosen precision: "everything on 1 Jan", "everything between 9 and 10 o'clock". Build LogStore:

const store = new LogStore();
store.put(1, "2017:01:01:23:59:59");
store.put(2, "2017:01:01:22:59:59");
store.put(3, "2016:01:01:00:00:00");

store.retrieve("2016:01:01:01:01:01", "2017:01:01:23:00:00", "Year"); // [3, 2, 1]
store.retrieve("2016:01:01:01:01:01", "2017:01:01:23:00:00", "Hour"); // [2, 1]

Ref. UR-1429 · © UIRound · uiround.com/questions/store-logs-by-timestamp-and-retrieve-them-by-year-month-day-hour-minute-or-second

Stuck? Take a hint

Try it in the editor

Run your code as often as you like. Submitting it to the full test suite is part of Pro.

Private, and saved in this browser as you type. All your notes are on My lists.

Every question and answer7 days, one payment