How to sort an array of arrays in ascending orderCreate ArrayList from arrayHow do I check if an array includes an object in JavaScript?How to append something to an array?How to insert an item into an array at a specific index (JavaScript)?Sort array of objects by string property valueHow do I empty an array in JavaScript?Loop through an array in JavaScriptHow to check if an object is an array?How do I remove a particular element from an array in JavaScript?For-each over an array in JavaScript?

What is this "opened" cube called?

What should be done with the carbon when using magic to get oxygen from carbon dioxide?

Is "prohibition against," a double negative?

Was it illegal to blaspheme God in Antioch in 360.-410.?

Printing a list as "a, b, c." using Python

Get contents before a colon

What caused the end of cybernetic implants?

Inspiration for failed idea?

Does the telecom provider need physical access to the SIM card to clone it?

How do I portray irrational anger in first person?

What is the practical impact of using System.Random which is not cryptographically random?

German equivalent to "going down the rabbit hole"

Sum and average calculator

How do I get my neighbour to stop disturbing with loud music?

Can authors email you PDFs of their textbook for free?

How can I improve my formal definitions

Small RAM 4 KB on the early Apple II?

Don't look at what I did there

Did the Apollo Guidance Computer really use 60% of the world's ICs in 1963?

In what language did Túrin converse with Mím?

How to understand payment due date for credit card?

How to investigate an unknown 1.5GB file named "sudo" in my Linux home directory?

Unexpected behavior after assignment of function object to function wrapper

Is Borg adaptation only temporary?



How to sort an array of arrays in ascending order


Create ArrayList from arrayHow do I check if an array includes an object in JavaScript?How to append something to an array?How to insert an item into an array at a specific index (JavaScript)?Sort array of objects by string property valueHow do I empty an array in JavaScript?Loop through an array in JavaScriptHow to check if an object is an array?How do I remove a particular element from an array in JavaScript?For-each over an array in JavaScript?






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








0















Information in an array:



scores = %w[ScoreA ScoreB ScoreC ScoreD ScoreE ScoreF ScoreG ScoreH ScoreI ScoreJ]


needs to be presented in ascending order of the golf scores.



Can anyone help sorting the output in ascending order?



golf = scores.map do |score_number|
print "Enter the score for #score_number:"
[score_number, gets.to_i]
end

puts golf.sort









share|improve this question





















  • 1





    "Any tips?" is hardly a proper question. Please have a look at to ask a good question and take your time to format the code properly. You can see a preview of your post in the bottom of the editing page.

    – dedObed
    Mar 27 at 23:25











  • @dedObed, Thank you for your input. Both are edited.

    – C_B
    Mar 27 at 23:30


















0















Information in an array:



scores = %w[ScoreA ScoreB ScoreC ScoreD ScoreE ScoreF ScoreG ScoreH ScoreI ScoreJ]


needs to be presented in ascending order of the golf scores.



Can anyone help sorting the output in ascending order?



golf = scores.map do |score_number|
print "Enter the score for #score_number:"
[score_number, gets.to_i]
end

puts golf.sort









share|improve this question





















  • 1





    "Any tips?" is hardly a proper question. Please have a look at to ask a good question and take your time to format the code properly. You can see a preview of your post in the bottom of the editing page.

    – dedObed
    Mar 27 at 23:25











  • @dedObed, Thank you for your input. Both are edited.

    – C_B
    Mar 27 at 23:30














0












0








0








Information in an array:



scores = %w[ScoreA ScoreB ScoreC ScoreD ScoreE ScoreF ScoreG ScoreH ScoreI ScoreJ]


needs to be presented in ascending order of the golf scores.



Can anyone help sorting the output in ascending order?



golf = scores.map do |score_number|
print "Enter the score for #score_number:"
[score_number, gets.to_i]
end

puts golf.sort









share|improve this question
















Information in an array:



scores = %w[ScoreA ScoreB ScoreC ScoreD ScoreE ScoreF ScoreG ScoreH ScoreI ScoreJ]


needs to be presented in ascending order of the golf scores.



Can anyone help sorting the output in ascending order?



golf = scores.map do |score_number|
print "Enter the score for #score_number:"
[score_number, gets.to_i]
end

puts golf.sort






arrays ruby






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 28 at 9:46









sawa

136k31 gold badges221 silver badges319 bronze badges




136k31 gold badges221 silver badges319 bronze badges










asked Mar 27 at 22:54









C_BC_B

41 bronze badge




41 bronze badge










  • 1





    "Any tips?" is hardly a proper question. Please have a look at to ask a good question and take your time to format the code properly. You can see a preview of your post in the bottom of the editing page.

    – dedObed
    Mar 27 at 23:25











  • @dedObed, Thank you for your input. Both are edited.

    – C_B
    Mar 27 at 23:30













  • 1





    "Any tips?" is hardly a proper question. Please have a look at to ask a good question and take your time to format the code properly. You can see a preview of your post in the bottom of the editing page.

    – dedObed
    Mar 27 at 23:25











  • @dedObed, Thank you for your input. Both are edited.

    – C_B
    Mar 27 at 23:30








1




1





"Any tips?" is hardly a proper question. Please have a look at to ask a good question and take your time to format the code properly. You can see a preview of your post in the bottom of the editing page.

– dedObed
Mar 27 at 23:25





"Any tips?" is hardly a proper question. Please have a look at to ask a good question and take your time to format the code properly. You can see a preview of your post in the bottom of the editing page.

– dedObed
Mar 27 at 23:25













@dedObed, Thank you for your input. Both are edited.

– C_B
Mar 27 at 23:30






@dedObed, Thank you for your input. Both are edited.

– C_B
Mar 27 at 23:30













2 Answers
2






active

oldest

votes


















4















Just use Array#sort with block



golf.sort a.last <=> b.last 


or Enumerable#sort_by



golf.sort_by 


The second variant can be shortened using Proc



golf.sort_by(&:last)





share|improve this answer



























  • @ray Your edit changes the code's intention. That is too much.

    – sawa
    Mar 28 at 9:43












  • You can address block as sort_by(&:last) with to format short in length.

    – ray
    Mar 28 at 9:48











  • @ray, I've updated my answer and added the link to explain it.

    – mechnicov
    Mar 28 at 10:04


















0















Just use Array#sort with block



golf.sort x, y
=> [["ScoreH", 1], ["ScoreB", 3], ["ScoreD", 4], ["ScoreF", 9], ["ScoreA", 10], ["ScoreJ", 23], ["ScoreG", 45], ["ScoreC", 67], ["ScoreI", 87], ["ScoreE", 88]]





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%2f55387704%2fhow-to-sort-an-array-of-arrays-in-ascending-order%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    4















    Just use Array#sort with block



    golf.sort a.last <=> b.last 


    or Enumerable#sort_by



    golf.sort_by 


    The second variant can be shortened using Proc



    golf.sort_by(&:last)





    share|improve this answer



























    • @ray Your edit changes the code's intention. That is too much.

      – sawa
      Mar 28 at 9:43












    • You can address block as sort_by(&:last) with to format short in length.

      – ray
      Mar 28 at 9:48











    • @ray, I've updated my answer and added the link to explain it.

      – mechnicov
      Mar 28 at 10:04















    4















    Just use Array#sort with block



    golf.sort a.last <=> b.last 


    or Enumerable#sort_by



    golf.sort_by 


    The second variant can be shortened using Proc



    golf.sort_by(&:last)





    share|improve this answer



























    • @ray Your edit changes the code's intention. That is too much.

      – sawa
      Mar 28 at 9:43












    • You can address block as sort_by(&:last) with to format short in length.

      – ray
      Mar 28 at 9:48











    • @ray, I've updated my answer and added the link to explain it.

      – mechnicov
      Mar 28 at 10:04













    4














    4










    4









    Just use Array#sort with block



    golf.sort a.last <=> b.last 


    or Enumerable#sort_by



    golf.sort_by 


    The second variant can be shortened using Proc



    golf.sort_by(&:last)





    share|improve this answer















    Just use Array#sort with block



    golf.sort a.last <=> b.last 


    or Enumerable#sort_by



    golf.sort_by 


    The second variant can be shortened using Proc



    golf.sort_by(&:last)






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Mar 28 at 10:01

























    answered Mar 27 at 23:41









    mechnicovmechnicov

    2,4412 gold badges9 silver badges24 bronze badges




    2,4412 gold badges9 silver badges24 bronze badges















    • @ray Your edit changes the code's intention. That is too much.

      – sawa
      Mar 28 at 9:43












    • You can address block as sort_by(&:last) with to format short in length.

      – ray
      Mar 28 at 9:48











    • @ray, I've updated my answer and added the link to explain it.

      – mechnicov
      Mar 28 at 10:04

















    • @ray Your edit changes the code's intention. That is too much.

      – sawa
      Mar 28 at 9:43












    • You can address block as sort_by(&:last) with to format short in length.

      – ray
      Mar 28 at 9:48











    • @ray, I've updated my answer and added the link to explain it.

      – mechnicov
      Mar 28 at 10:04
















    @ray Your edit changes the code's intention. That is too much.

    – sawa
    Mar 28 at 9:43






    @ray Your edit changes the code's intention. That is too much.

    – sawa
    Mar 28 at 9:43














    You can address block as sort_by(&:last) with to format short in length.

    – ray
    Mar 28 at 9:48





    You can address block as sort_by(&:last) with to format short in length.

    – ray
    Mar 28 at 9:48













    @ray, I've updated my answer and added the link to explain it.

    – mechnicov
    Mar 28 at 10:04





    @ray, I've updated my answer and added the link to explain it.

    – mechnicov
    Mar 28 at 10:04













    0















    Just use Array#sort with block



    golf.sort x, y
    => [["ScoreH", 1], ["ScoreB", 3], ["ScoreD", 4], ["ScoreF", 9], ["ScoreA", 10], ["ScoreJ", 23], ["ScoreG", 45], ["ScoreC", 67], ["ScoreI", 87], ["ScoreE", 88]]





    share|improve this answer































      0















      Just use Array#sort with block



      golf.sort x, y
      => [["ScoreH", 1], ["ScoreB", 3], ["ScoreD", 4], ["ScoreF", 9], ["ScoreA", 10], ["ScoreJ", 23], ["ScoreG", 45], ["ScoreC", 67], ["ScoreI", 87], ["ScoreE", 88]]





      share|improve this answer





























        0














        0










        0









        Just use Array#sort with block



        golf.sort x, y
        => [["ScoreH", 1], ["ScoreB", 3], ["ScoreD", 4], ["ScoreF", 9], ["ScoreA", 10], ["ScoreJ", 23], ["ScoreG", 45], ["ScoreC", 67], ["ScoreI", 87], ["ScoreE", 88]]





        share|improve this answer















        Just use Array#sort with block



        golf.sort x, y
        => [["ScoreH", 1], ["ScoreB", 3], ["ScoreD", 4], ["ScoreF", 9], ["ScoreA", 10], ["ScoreJ", 23], ["ScoreG", 45], ["ScoreC", 67], ["ScoreI", 87], ["ScoreE", 88]]






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Mar 28 at 7:18









        Ajay Barot

        1,4371 gold badge19 silver badges33 bronze badges




        1,4371 gold badge19 silver badges33 bronze badges










        answered Mar 28 at 4:50









        Srinidhi GsSrinidhi Gs

        604 bronze badges




        604 bronze badges






























            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%2f55387704%2fhow-to-sort-an-array-of-arrays-in-ascending-order%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

            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

            용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

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