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 8067281
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:14:26+00:00 2026-06-05T12:14:26+00:00

This might get a bit confusing and I’m not sure if it’s possible, but

  • 0

This might get a bit confusing and I’m not sure if it’s possible, but I would appreciate any help.
I have the following arrays (the items and number of lists might change, this is just an example):

var list_1 = ["A - 2" , "E - 5" , "C - 7"];
var list_2 = ["D - 2" , "A - 2" , "E - 3"];
var list_3 = ["C - 1" , "E - 8" , "A - 7"];

My expected output is:

var final = ["A - 2" , "C - 1" , "D - 2" , "E - 3"];

What I’m trying to do:

I’m trying to figure out how to go through each array item, see if the letter in the beginning of the item exists in the previous array and if the number in the item is lower than the previous item, replace it in the ‘final’ list.

Any ideas, or is this not possible?

jQuery is acceptable

  • 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-05T12:14:27+00:00Added an answer on June 5, 2026 at 12:14 pm
    var list_1 = ["A - 2" , "E - 5" , "C - 7"];
    var list_2 = ["D - 2" , "A - 2" , "E - 3"];
    var list_3 = ["C - 1" , "E - 8" , "A - 7"];
    

    First, you merge the lists (third + second + first):

    var list = list_3.concat(list_2).concat(list_1);
    

    Create a map into which you’re going to put the lowest number for each letter:

    var final_map = {};
    

    Loop through all items splitting each item to the letter (parts[0]) and the number (parts[1]).

    You get the currently lowest number for the given letter. If there is no number or the new number is lower than the currently lowest one, you update the map.

    list.forEach(function (item) {
      var parts = item.split(' - ');
      var current = final_map[parts[0]];
    
      if (!current || parts[1] < current) {
        final_map[parts[0]] = parts[1];
      }
    });
    

    Finally, you convert the map to an array.

    var final = [];
    Object.keys(final_map).sort().forEach(function (key) {
      final.push(key + ' - ' + final_map[key]);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This might get a little confusing as I have tried everything to make this
This might have to be broken down a bit but what i want to
This might be a bit tricky setup but... I have this Silverlight project that
Bear with me—this might be a bit confusing! I have a javascript that adds
my question might be a bit confusing, but here is what i would like
This might be a bit of a trivial question, but can't I get django
I expect this might get some downvotes / closevotes but I'm going to ask
This might sound daft but how do you get silverlight to run as a
This might seam like a strange question but.... public string MyProperty { get {
I have read a bit about lazy loading in c# and this might seem

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.