Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

190
Views
find the amount of users in a certain duration

I'm looking to find the amount of users based on a ID in a certain time frame

My starting time is 1512709024000 and my end time is 10 mins

I need to group all the users together from the object below

 [{
         "name": "user1",
         "id": "1",
         "timestamp": 1512754583000
     },
     {
         "name": "user2",
         "id": "1",
         "timestamp": 1512754631000
     },
    {
        "name": "user3",
        "id": "2",
        "timestamp": 1512709065294
    },
    {
        "name": "user4",
        "id": "2",
        "timestamp": 1512711000000
    },
    {
        "name": "user4",
        "id": "1",
        "timestamp": 1512754436000
    }

 ]
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You can use a filter for this to work

const items = [{
    "name": "user1",
    "id": "1",
    "timestamp": 1512754583000
  },
  {
    "name": "user2",
    "id": "1",
    "timestamp": 1512754631000
  },
  {
    "name": "user3",
    "id": "2",
    "timestamp": 1512709065294
  },
  {
    "name": "user4",
    "id": "2",
    "timestamp": 1512711000000
  },
  {
    "name": "user4",
    "id": "1",
    "timestamp": 1512754436000
  }
];

const timestamp = 1512709024000;
const limit = timestamp + 10 * 60 * 1000;

console.log(items.filter((item) => item.timestamp >= timestamp && item.timestamp <= limit));

about 4 years ago · Juan Pablo Isaza Report

0

const a = [{
         "name": "user1",
         "id": "1",
         "timestamp": 1512754583000
     },
     {
         "name": "user2",
         "id": "1",
         "timestamp": 1512754631000
     },
    {
        "name": "user3",
        "id": "2",
        "timestamp": 1512709065294
    },
    {
        "name": "user4",
        "id": "2",
        "timestamp": 1512711000000
    },
    {
        "name": "user4",
        "id": "1",
        "timestamp": 1512754436000
    }

 ]
 
function filterByTimeAndId(arr, startTimeInMs, noOfMinutes, id) {
  const noOfMillis = noOfMinutes * 60 * 1000;
  const endTimeInMs = startTimeInMs + noOfMillis;
  return arr.filter(a => a.id === id && a.timestamp >= startTimeInMs && a.timestamp <= endTimeInMs);
}

console.log(filterByTimeAndId(a, 1512709024000, 10, 1));

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!