Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8266091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T05:02:03+00:00 2026-06-08T05:02:03+00:00

I have a 2d array: arr = [ [John, 17], [John, 17], [Abe, 14],

  • 0

I have a 2d array:

arr = [
  ["John", 17],
  ["John", 17],
  ["Abe", 14],
  ["Kobian", 18],
  ["Hony", 16],
  ["Mony", 19],
  ["John", 18],
  ["Hari", 15],
]

I want to see unique results and sorted alphabetically so that no same name is repeated.
If names are different and age is same then select one which is not repeated and is lesser age.

I worked a lot but didn’t found how to solve it… thanks in advance for the answers…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T05:02:06+00:00Added an answer on June 8, 2026 at 5:02 am
    arr.group_by {|e| e[0] }.map {|k,v| v.min}.sort
    
    => [["Abe", 14], ["Hari", 15], ["Hony", 16], ["John", 17], ["Kobian", 18], ["Mony", 19]]
    

    and to keep different ages:

    require 'set'
    Set.new(arr).sort
    
    => [["Abe", 14], ["Hari", 15], ["Hony", 16], ["John", 17], ["John", 18], ["Kobian", 18], ["Mony", 19]]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say I have an array like int arr[10][10]; Now i want to initialize
i have an array: arr = ['a', 'b', 'c', ... ] i want it
I have an array ele , and I want to populate another array arr
I have an array as arr = [1,2,3,4,6,7,8,9] Now I want to check if
I have an array of int pointers int* arr[MAX]; and I want to store
I have an array like this arr = [orange,red,black,white] I want to augment the
Supposed i have an array int[] arr = {1,2,3,4} I want to convert it
Hi when I have an array in actionscript var arr : Array = new
Let's say I have array of bytes: byte[] arr = new byte[] { 0,
I have an array of integers in string form: var arr = new string[]

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.