Finding the maximum property under a value
I have a list of objects, each with its properties.
I am trying to find a specific object in this list with this .find although I can't figure out how to find the maximum value of one of it's properties under a certain value.
let x = this.state.pricing_adjustments_view.filter((e) => {
return e.location_id === this.state.selectedLocation,
e.car_model_id === this.state.selectedCar,
moment(e.calendar_day).isSame(this.state.from, "day"),
_.max(e.minimum_duration) <= duration
})
Here it's the e.minimum_duration. I want to find the biggest value, but that is under "duration"
I am trying it with "lodash", here represented by the "_".
I am open to other possibilities.
this.state.pricing_adjustments_view is an array of objects, and you could say that for each object, the "UNIQUE" key is its "location_id", "car_model_id", "calendar_day" and "minimum_duration".
So there are several objects that are the same if we only consider "location_id", "car_model_id", "calendar_day", and then they have different "minimum_duration". I need to get the one that has the highest "minimum_duration".
javascript lodash
|
show 4 more comments
I have a list of objects, each with its properties.
I am trying to find a specific object in this list with this .find although I can't figure out how to find the maximum value of one of it's properties under a certain value.
let x = this.state.pricing_adjustments_view.filter((e) => {
return e.location_id === this.state.selectedLocation,
e.car_model_id === this.state.selectedCar,
moment(e.calendar_day).isSame(this.state.from, "day"),
_.max(e.minimum_duration) <= duration
})
Here it's the e.minimum_duration. I want to find the biggest value, but that is under "duration"
I am trying it with "lodash", here represented by the "_".
I am open to other possibilities.
this.state.pricing_adjustments_view is an array of objects, and you could say that for each object, the "UNIQUE" key is its "location_id", "car_model_id", "calendar_day" and "minimum_duration".
So there are several objects that are the same if we only consider "location_id", "car_model_id", "calendar_day", and then they have different "minimum_duration". I need to get the one that has the highest "minimum_duration".
javascript lodash
1
Pls provide some example of input and expected output.
– Nitish Narang
Nov 23 '18 at 20:07
return with a check and comma operator? either some code is missing or it makes no sense.
– Nina Scholz
Nov 23 '18 at 20:07
@NinaScholz it's how i usually do it, .filter((e) => {return e.thing = thing, e.thing = thing}) and it works
– Valenti
Nov 23 '18 at 20:09
1
I'm not certain there is enough detail here for us to help you, consider reading up on Minimal, Complete, Verifieable Example
– D Lowther
Nov 23 '18 at 20:10
for examplee.location_id === this.state.selectedLocation
has nothing to do with the rest. it is not use in anif
clause, nor as expression as return value or as part of a ternary.
– Nina Scholz
Nov 23 '18 at 20:11
|
show 4 more comments
I have a list of objects, each with its properties.
I am trying to find a specific object in this list with this .find although I can't figure out how to find the maximum value of one of it's properties under a certain value.
let x = this.state.pricing_adjustments_view.filter((e) => {
return e.location_id === this.state.selectedLocation,
e.car_model_id === this.state.selectedCar,
moment(e.calendar_day).isSame(this.state.from, "day"),
_.max(e.minimum_duration) <= duration
})
Here it's the e.minimum_duration. I want to find the biggest value, but that is under "duration"
I am trying it with "lodash", here represented by the "_".
I am open to other possibilities.
this.state.pricing_adjustments_view is an array of objects, and you could say that for each object, the "UNIQUE" key is its "location_id", "car_model_id", "calendar_day" and "minimum_duration".
So there are several objects that are the same if we only consider "location_id", "car_model_id", "calendar_day", and then they have different "minimum_duration". I need to get the one that has the highest "minimum_duration".
javascript lodash
I have a list of objects, each with its properties.
I am trying to find a specific object in this list with this .find although I can't figure out how to find the maximum value of one of it's properties under a certain value.
let x = this.state.pricing_adjustments_view.filter((e) => {
return e.location_id === this.state.selectedLocation,
e.car_model_id === this.state.selectedCar,
moment(e.calendar_day).isSame(this.state.from, "day"),
_.max(e.minimum_duration) <= duration
})
Here it's the e.minimum_duration. I want to find the biggest value, but that is under "duration"
I am trying it with "lodash", here represented by the "_".
I am open to other possibilities.
this.state.pricing_adjustments_view is an array of objects, and you could say that for each object, the "UNIQUE" key is its "location_id", "car_model_id", "calendar_day" and "minimum_duration".
So there are several objects that are the same if we only consider "location_id", "car_model_id", "calendar_day", and then they have different "minimum_duration". I need to get the one that has the highest "minimum_duration".
javascript lodash
javascript lodash
edited Nov 23 '18 at 20:16
Valenti
asked Nov 23 '18 at 20:06
ValentiValenti
32
32
1
Pls provide some example of input and expected output.
– Nitish Narang
Nov 23 '18 at 20:07
return with a check and comma operator? either some code is missing or it makes no sense.
– Nina Scholz
Nov 23 '18 at 20:07
@NinaScholz it's how i usually do it, .filter((e) => {return e.thing = thing, e.thing = thing}) and it works
– Valenti
Nov 23 '18 at 20:09
1
I'm not certain there is enough detail here for us to help you, consider reading up on Minimal, Complete, Verifieable Example
– D Lowther
Nov 23 '18 at 20:10
for examplee.location_id === this.state.selectedLocation
has nothing to do with the rest. it is not use in anif
clause, nor as expression as return value or as part of a ternary.
– Nina Scholz
Nov 23 '18 at 20:11
|
show 4 more comments
1
Pls provide some example of input and expected output.
– Nitish Narang
Nov 23 '18 at 20:07
return with a check and comma operator? either some code is missing or it makes no sense.
– Nina Scholz
Nov 23 '18 at 20:07
@NinaScholz it's how i usually do it, .filter((e) => {return e.thing = thing, e.thing = thing}) and it works
– Valenti
Nov 23 '18 at 20:09
1
I'm not certain there is enough detail here for us to help you, consider reading up on Minimal, Complete, Verifieable Example
– D Lowther
Nov 23 '18 at 20:10
for examplee.location_id === this.state.selectedLocation
has nothing to do with the rest. it is not use in anif
clause, nor as expression as return value or as part of a ternary.
– Nina Scholz
Nov 23 '18 at 20:11
1
1
Pls provide some example of input and expected output.
– Nitish Narang
Nov 23 '18 at 20:07
Pls provide some example of input and expected output.
– Nitish Narang
Nov 23 '18 at 20:07
return with a check and comma operator? either some code is missing or it makes no sense.
– Nina Scholz
Nov 23 '18 at 20:07
return with a check and comma operator? either some code is missing or it makes no sense.
– Nina Scholz
Nov 23 '18 at 20:07
@NinaScholz it's how i usually do it, .filter((e) => {return e.thing = thing, e.thing = thing}) and it works
– Valenti
Nov 23 '18 at 20:09
@NinaScholz it's how i usually do it, .filter((e) => {return e.thing = thing, e.thing = thing}) and it works
– Valenti
Nov 23 '18 at 20:09
1
1
I'm not certain there is enough detail here for us to help you, consider reading up on Minimal, Complete, Verifieable Example
– D Lowther
Nov 23 '18 at 20:10
I'm not certain there is enough detail here for us to help you, consider reading up on Minimal, Complete, Verifieable Example
– D Lowther
Nov 23 '18 at 20:10
for example
e.location_id === this.state.selectedLocation
has nothing to do with the rest. it is not use in an if
clause, nor as expression as return value or as part of a ternary.– Nina Scholz
Nov 23 '18 at 20:11
for example
e.location_id === this.state.selectedLocation
has nothing to do with the rest. it is not use in an if
clause, nor as expression as return value or as part of a ternary.– Nina Scholz
Nov 23 '18 at 20:11
|
show 4 more comments
0
active
oldest
votes
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%2f53452398%2ffinding-the-maximum-property-under-a-value%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2f53452398%2ffinding-the-maximum-property-under-a-value%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
1
Pls provide some example of input and expected output.
– Nitish Narang
Nov 23 '18 at 20:07
return with a check and comma operator? either some code is missing or it makes no sense.
– Nina Scholz
Nov 23 '18 at 20:07
@NinaScholz it's how i usually do it, .filter((e) => {return e.thing = thing, e.thing = thing}) and it works
– Valenti
Nov 23 '18 at 20:09
1
I'm not certain there is enough detail here for us to help you, consider reading up on Minimal, Complete, Verifieable Example
– D Lowther
Nov 23 '18 at 20:10
for example
e.location_id === this.state.selectedLocation
has nothing to do with the rest. it is not use in anif
clause, nor as expression as return value or as part of a ternary.– Nina Scholz
Nov 23 '18 at 20:11