Finding the maximum property under a value












0















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".










share|improve this question




















  • 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 an if clause, nor as expression as return value or as part of a ternary.

    – Nina Scholz
    Nov 23 '18 at 20:11
















0















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".










share|improve this question




















  • 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 an if clause, nor as expression as return value or as part of a ternary.

    – Nina Scholz
    Nov 23 '18 at 20:11














0












0








0








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".










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 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














  • 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 an if 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












1 Answer
1






active

oldest

votes


















0














Ok,



You say it's the minimum_duration that interests you. In order to find the biggest (or smallest..) It's simple to just order pricing_adjustments_view by minimum_duration and take it's highest value.



So you can basically do following using lodash lib.



// sort dataa..
let sorted = _.sortBy(this.state.pricing_adjustments_view, 'minimum_duration');

// take last in list!
let has_highest_minimum_duration = sorted[sorted.length-1];





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%2f53452398%2ffinding-the-maximum-property-under-a-value%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














    Ok,



    You say it's the minimum_duration that interests you. In order to find the biggest (or smallest..) It's simple to just order pricing_adjustments_view by minimum_duration and take it's highest value.



    So you can basically do following using lodash lib.



    // sort dataa..
    let sorted = _.sortBy(this.state.pricing_adjustments_view, 'minimum_duration');

    // take last in list!
    let has_highest_minimum_duration = sorted[sorted.length-1];





    share|improve this answer




























      0














      Ok,



      You say it's the minimum_duration that interests you. In order to find the biggest (or smallest..) It's simple to just order pricing_adjustments_view by minimum_duration and take it's highest value.



      So you can basically do following using lodash lib.



      // sort dataa..
      let sorted = _.sortBy(this.state.pricing_adjustments_view, 'minimum_duration');

      // take last in list!
      let has_highest_minimum_duration = sorted[sorted.length-1];





      share|improve this answer


























        0












        0








        0







        Ok,



        You say it's the minimum_duration that interests you. In order to find the biggest (or smallest..) It's simple to just order pricing_adjustments_view by minimum_duration and take it's highest value.



        So you can basically do following using lodash lib.



        // sort dataa..
        let sorted = _.sortBy(this.state.pricing_adjustments_view, 'minimum_duration');

        // take last in list!
        let has_highest_minimum_duration = sorted[sorted.length-1];





        share|improve this answer













        Ok,



        You say it's the minimum_duration that interests you. In order to find the biggest (or smallest..) It's simple to just order pricing_adjustments_view by minimum_duration and take it's highest value.



        So you can basically do following using lodash lib.



        // sort dataa..
        let sorted = _.sortBy(this.state.pricing_adjustments_view, 'minimum_duration');

        // take last in list!
        let has_highest_minimum_duration = sorted[sorted.length-1];






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 18 at 22:37









        Silvan BregySilvan Bregy

        60829




        60829
































            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%2f53452398%2ffinding-the-maximum-property-under-a-value%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

            404 Error Contact Form 7 ajax form submitting

            How to know if a Active Directory user can login interactively

            TypeError: fit_transform() missing 1 required positional argument: 'X'