How do I sort items into objects via timestampsHow do you get a timestamp in JavaScript?How do I check if an array includes an object in JavaScript?Should I use the datetime or timestamp data type in MySQL?How to insert an item into an array at a specific index (JavaScript)?How do I sort a dictionary by value?Sorting an array of JavaScript objects by propertySort array of objects by string property valueHow to check if an object is an array?How do I remove a particular element from an array in JavaScript?How to pair socks from a pile efficiently?

Does 5e have an equivalent of the Psychic Paper from Doctor Who?

What's the difference between a type and a kind?

How did the IEC decide to create kibibytes?

Taking advantage when the HR forgets to communicate the rules

Would the Life cleric's Disciple of Life feature supercharge the Regenerate spell?

Is there a way to change the aspect ratio of a DNG file?

Why is there paternal, for fatherly, fraternal, for brotherly, but no similar word for sons?

In the Seventh Seal why does Death let the chess game happen?

What is it called when the tritone is added to a minor scale?

What exactly does "Stick Sensitivity" do in Smash Ultimate custom controls?

What is the shape of the upper boundary of water hitting a screen?

Shipped package arrived - didn't order, possible scam?

Red and White Squares

Are "confidant" and "confident" homophones?

What are some bad ways to subvert tropes?

Taking my Ph.D. advisor out for dinner after graduation

Why do Martians have to wear space helmets?

Is it acceptable that I plot a time-series figure with years increasing from right to left?

What is the difference between an "empty interior" and a "hole" in topology?

How can select a specific triangle in my Delaunay mesh?

How did Einstein know the speed of light was constant?

Is kapton suitable for use as high voltage insulation?

What is the highest level of accuracy in motion control a Victorian society could achieve?

Question about targeting a Hexproof creature



How do I sort items into objects via timestamps


How do you get a timestamp in JavaScript?How do I check if an array includes an object in JavaScript?Should I use the datetime or timestamp data type in MySQL?How to insert an item into an array at a specific index (JavaScript)?How do I sort a dictionary by value?Sorting an array of JavaScript objects by propertySort array of objects by string property valueHow to check if an object is an array?How do I remove a particular element from an array in JavaScript?How to pair socks from a pile efficiently?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I have two arrays of objects, which I want to combine into one array in order of the timestamps that are a part of each object. The first array is an exact second, and the second array is a range of an hour. I want to input the 'humidity' values in the array with the exact timestamps into the one with the hourly ranges, according to where they fit in, time wise. How do I do this in typescript? Both arrays/objects are sorted by time.



For example:



[id: 1, timestampUtc: "2019-02-22T08:24:00Z", humidity: 74,
id: 2, timestampUtc: "2019-02-24T06:20:00Z", humidity: 39,
id: 3, timestampUtc: "2019-02-26T020:03:00Z", humidity: 35]


and



[id: 4, starttimestampUtc: "2019-02-22T08:00:00Z", endtimestampUtc: "2019-02-22T09:00:00Z", precipitation: .03,
id: 5, starttimestampUtc: "2019-02-24T06:00:00Z", endtimestampUtc: "2019-02-24T07:00:00Z", precipitation: .3,
id: 6, starttimestampUtc: "2019-02-26T020:00:00Z",endtimestampUtc: "2019-02-26T021:00:00Z", precipitation: .12]


to look like:



[id: 4, starttimestampUtc: "2019-02-22T08:00:00Z", endtimestampUtc: "2019-02-22T09:00:00Z", precipitation: .03, humidity: 74,
id: 5, starttimestampUtc: "2019-02-24T06:00:00Z", endtimestampUtc: "2019-02-24T07:00:00Z", precipitation: .3, humidity: 39,
id: 6, starttimestampUtc: "2019-02-26T020:00:00Z", endtimestampUtc: "2019-02-26T021:00:00Z", precipitation: .12, , humidity: 35]









share|improve this question






























    0















    I have two arrays of objects, which I want to combine into one array in order of the timestamps that are a part of each object. The first array is an exact second, and the second array is a range of an hour. I want to input the 'humidity' values in the array with the exact timestamps into the one with the hourly ranges, according to where they fit in, time wise. How do I do this in typescript? Both arrays/objects are sorted by time.



    For example:



    [id: 1, timestampUtc: "2019-02-22T08:24:00Z", humidity: 74,
    id: 2, timestampUtc: "2019-02-24T06:20:00Z", humidity: 39,
    id: 3, timestampUtc: "2019-02-26T020:03:00Z", humidity: 35]


    and



    [id: 4, starttimestampUtc: "2019-02-22T08:00:00Z", endtimestampUtc: "2019-02-22T09:00:00Z", precipitation: .03,
    id: 5, starttimestampUtc: "2019-02-24T06:00:00Z", endtimestampUtc: "2019-02-24T07:00:00Z", precipitation: .3,
    id: 6, starttimestampUtc: "2019-02-26T020:00:00Z",endtimestampUtc: "2019-02-26T021:00:00Z", precipitation: .12]


    to look like:



    [id: 4, starttimestampUtc: "2019-02-22T08:00:00Z", endtimestampUtc: "2019-02-22T09:00:00Z", precipitation: .03, humidity: 74,
    id: 5, starttimestampUtc: "2019-02-24T06:00:00Z", endtimestampUtc: "2019-02-24T07:00:00Z", precipitation: .3, humidity: 39,
    id: 6, starttimestampUtc: "2019-02-26T020:00:00Z", endtimestampUtc: "2019-02-26T021:00:00Z", precipitation: .12, , humidity: 35]









    share|improve this question


























      0












      0








      0








      I have two arrays of objects, which I want to combine into one array in order of the timestamps that are a part of each object. The first array is an exact second, and the second array is a range of an hour. I want to input the 'humidity' values in the array with the exact timestamps into the one with the hourly ranges, according to where they fit in, time wise. How do I do this in typescript? Both arrays/objects are sorted by time.



      For example:



      [id: 1, timestampUtc: "2019-02-22T08:24:00Z", humidity: 74,
      id: 2, timestampUtc: "2019-02-24T06:20:00Z", humidity: 39,
      id: 3, timestampUtc: "2019-02-26T020:03:00Z", humidity: 35]


      and



      [id: 4, starttimestampUtc: "2019-02-22T08:00:00Z", endtimestampUtc: "2019-02-22T09:00:00Z", precipitation: .03,
      id: 5, starttimestampUtc: "2019-02-24T06:00:00Z", endtimestampUtc: "2019-02-24T07:00:00Z", precipitation: .3,
      id: 6, starttimestampUtc: "2019-02-26T020:00:00Z",endtimestampUtc: "2019-02-26T021:00:00Z", precipitation: .12]


      to look like:



      [id: 4, starttimestampUtc: "2019-02-22T08:00:00Z", endtimestampUtc: "2019-02-22T09:00:00Z", precipitation: .03, humidity: 74,
      id: 5, starttimestampUtc: "2019-02-24T06:00:00Z", endtimestampUtc: "2019-02-24T07:00:00Z", precipitation: .3, humidity: 39,
      id: 6, starttimestampUtc: "2019-02-26T020:00:00Z", endtimestampUtc: "2019-02-26T021:00:00Z", precipitation: .12, , humidity: 35]









      share|improve this question
















      I have two arrays of objects, which I want to combine into one array in order of the timestamps that are a part of each object. The first array is an exact second, and the second array is a range of an hour. I want to input the 'humidity' values in the array with the exact timestamps into the one with the hourly ranges, according to where they fit in, time wise. How do I do this in typescript? Both arrays/objects are sorted by time.



      For example:



      [id: 1, timestampUtc: "2019-02-22T08:24:00Z", humidity: 74,
      id: 2, timestampUtc: "2019-02-24T06:20:00Z", humidity: 39,
      id: 3, timestampUtc: "2019-02-26T020:03:00Z", humidity: 35]


      and



      [id: 4, starttimestampUtc: "2019-02-22T08:00:00Z", endtimestampUtc: "2019-02-22T09:00:00Z", precipitation: .03,
      id: 5, starttimestampUtc: "2019-02-24T06:00:00Z", endtimestampUtc: "2019-02-24T07:00:00Z", precipitation: .3,
      id: 6, starttimestampUtc: "2019-02-26T020:00:00Z",endtimestampUtc: "2019-02-26T021:00:00Z", precipitation: .12]


      to look like:



      [id: 4, starttimestampUtc: "2019-02-22T08:00:00Z", endtimestampUtc: "2019-02-22T09:00:00Z", precipitation: .03, humidity: 74,
      id: 5, starttimestampUtc: "2019-02-24T06:00:00Z", endtimestampUtc: "2019-02-24T07:00:00Z", precipitation: .3, humidity: 39,
      id: 6, starttimestampUtc: "2019-02-26T020:00:00Z", endtimestampUtc: "2019-02-26T021:00:00Z", precipitation: .12, , humidity: 35]






      arrays typescript sorting timestamp






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 25 at 19:53







      LaurenAH

















      asked Mar 25 at 19:47









      LaurenAHLaurenAH

      2332 silver badges11 bronze badges




      2332 silver badges11 bronze badges






















          1 Answer
          1






          active

          oldest

          votes


















          0














          I was able to do this by converting the UTC timestamps into date objects. The following code seemed to work for me, where a and b are your two arrays. I also noticed that there is an extra 0 in the timestamps of the final element of each array.



          b.map((element) => 
          let entry = a.find((e) =>
          let d = new Date(e.timestampUtc)
          let start = new Date(element.starttimestampUtc)
          let end = new Date(element.endtimestampUtc)
          return (d >= start && d <= end)
          )
          if(entry !== undefined)
          element.humidity = entry.humidity

          return element

          )





          share|improve this answer
























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55345371%2fhow-do-i-sort-items-into-objects-via-timestamps%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            I was able to do this by converting the UTC timestamps into date objects. The following code seemed to work for me, where a and b are your two arrays. I also noticed that there is an extra 0 in the timestamps of the final element of each array.



            b.map((element) => 
            let entry = a.find((e) =>
            let d = new Date(e.timestampUtc)
            let start = new Date(element.starttimestampUtc)
            let end = new Date(element.endtimestampUtc)
            return (d >= start && d <= end)
            )
            if(entry !== undefined)
            element.humidity = entry.humidity

            return element

            )





            share|improve this answer





























              0














              I was able to do this by converting the UTC timestamps into date objects. The following code seemed to work for me, where a and b are your two arrays. I also noticed that there is an extra 0 in the timestamps of the final element of each array.



              b.map((element) => 
              let entry = a.find((e) =>
              let d = new Date(e.timestampUtc)
              let start = new Date(element.starttimestampUtc)
              let end = new Date(element.endtimestampUtc)
              return (d >= start && d <= end)
              )
              if(entry !== undefined)
              element.humidity = entry.humidity

              return element

              )





              share|improve this answer



























                0












                0








                0







                I was able to do this by converting the UTC timestamps into date objects. The following code seemed to work for me, where a and b are your two arrays. I also noticed that there is an extra 0 in the timestamps of the final element of each array.



                b.map((element) => 
                let entry = a.find((e) =>
                let d = new Date(e.timestampUtc)
                let start = new Date(element.starttimestampUtc)
                let end = new Date(element.endtimestampUtc)
                return (d >= start && d <= end)
                )
                if(entry !== undefined)
                element.humidity = entry.humidity

                return element

                )





                share|improve this answer















                I was able to do this by converting the UTC timestamps into date objects. The following code seemed to work for me, where a and b are your two arrays. I also noticed that there is an extra 0 in the timestamps of the final element of each array.



                b.map((element) => 
                let entry = a.find((e) =>
                let d = new Date(e.timestampUtc)
                let start = new Date(element.starttimestampUtc)
                let end = new Date(element.endtimestampUtc)
                return (d >= start && d <= end)
                )
                if(entry !== undefined)
                element.humidity = entry.humidity

                return element

                )






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Mar 25 at 20:24

























                answered Mar 25 at 20:13









                Cody DeckardCody Deckard

                11 bronze badge




                11 bronze badge


















                    Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







                    Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55345371%2fhow-do-i-sort-items-into-objects-via-timestamps%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                    SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                    은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현