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

                    How to preserve electronics (computers, tablets and phones) for hundreds of years Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) The network's official Twitter account is up and running again. What content…How might modern humans leave a message for 50,000 years?How would an aquatic race develop computers?How do we make computers care for human life?Keeping supplies for 1000 yearsWhat will cell phones become in 100 years?What body armor protects against a laser?Could a society attain 1800s technology if limited to using copper and bronze?Electricity power (magic) and electronicsScavenging metal resources in post-apocalypse after 100 yearsWhy would precursors create devices that can survive and still work after hundreds of years?

                    155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해

                    해남서초등학교 학교 연혁 학교 동문 외부 링크 둘러보기 메뉴북위 34° 34′ 21″ 동경 126° 35′ 50″ / 북위 34.5726385° 동경 126.5972670°  / 34.5726385; 126.5972670해남서초등학교eh