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

133
Views
get difference with previous date

I have the following JSON , how do i get difference between the previous date for num_followers for each website ?

like for website yqq on 15-02-2022 I need to get the difference between the num_followers from 14-02-2022 and update num_followers with difference value

[
    {
        "date": "2022-02-15",
        "websites": [
            {
                "website_name": "yqq",
                "num_followers": "454421"
            },
            {
                "website_name": "soundcloud",
                "num_followers": "757127"
            },
            {
                "website_name": "twitter",
                "num_followers": "21779161"
            },
            {
                "website_name": "soundcloud",
                "num_followers": "757054"
            },
            {
                "website_name": "triller",
                "num_followers": "5196"
            },
        ]
    },
    {
        "date": "2022-02-14",
        "websites": [
            {
                "website_name": "yqq",
                "num_followers": "123058219"
            },
            {
                "website_name": "triller",
                "num_followers": "5195"
            },
            {
                "website_name": "tiktok",
                "num_followers": "17100000"
            },
            {
                "website_name": "instagram",
                "num_followers": "123059626"
            },
            {
                "website_name": "tiktok",
                "num_followers": "17100000"
            },
            {
                "website_name": "tiktok",
                "num_followers": "17100000"
            },
            {
                "website_name": "soundcloud",
                "num_followers": "756956"
            },
        ]
    
    }
]
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Following worked for me thanks to @Bravo

rdiff = [];
          for (var k = 0; k < r.length; k++) {

            if (typeof r[k + 1] != 'undefined') {

              var differences = r[k].websites.map(function (_ref) {
                var _r$websites$find;

                var website_name = _ref.website_name,
                  num_followers = _ref.num_followers,
                  website_id = _ref.website_id;
                return {
                  website_name: website_name,
                  website_id: website_id,
                  num_followers: num_followers - (((_r$websites$find = r[k + 1].websites.find(function (_ref2) {
                    var x = _ref2.website_name;
                    return x === website_name;
                  })) === null || _r$websites$find === void 0 ? void 0 : _r$websites$find.num_followers) || 0)
                };
              });

              // console.log(differences);
              diff = {
                "date": r[k].date,
                "websites": differences
              }
              rdiff.push(diff);

            }
          }

          // console.log(rdiff);
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!