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;
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
add a comment |
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
add a comment |
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
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
arrays typescript sorting timestamp
edited Mar 25 at 19:53
LaurenAH
asked Mar 25 at 19:47


LaurenAHLaurenAH
2332 silver badges11 bronze badges
2332 silver badges11 bronze badges
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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
)
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
)
add a comment |
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
)
add a comment |
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
)
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
)
edited Mar 25 at 20:24
answered Mar 25 at 20:13
Cody DeckardCody Deckard
11 bronze badge
11 bronze badge
add a comment |
add a comment |
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.
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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