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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:19:09+00:00 2026-05-27T03:19:09+00:00

Assuming I have the following Javascript structure: [ { hash: fe5642d26d04cc7e7d47daa426da2a79e244bdcbae1594a12578f0d6fe03082e, path: /Users/justin/test/node-w.tar.gz },

  • 0

Assuming I have the following Javascript structure:

[
  {
    "hash": "fe5642d26d04cc7e7d47daa426da2a79e244bdcbae1594a12578f0d6fe03082e",
    "path": "/Users/justin/test/node-w.tar.gz"
  },
  {
    "hash": "b1adffc1988b7339c7d4c59310fb3a64ce89e776a4924d492e819a08a7dce3fd",
    "path": "/Users/justin/test/level-1/level-1-1/music.mp3"
  },
  {
    "hash": "fe5642d26d04cc7e7d47daa426da2a79e244bdcbae1594a12578f0d6fe03082e",
    "path": "/Users/justin/test/level-1/level-1-1/node-z.tar.gz"
  },
  {
    "hash": "2e456c8de66a4ab6cf929d52bd6928b2d0096a8116891ade3dde9588c5f6b3c2",
    "path": "/Users/justin/test/logo_large.psd"
  },
  {
    "hash": "fe5642d26d04cc7e7d47daa426da2a79e244bdcbae1594a12578f0d6fe03082e",
    "path": "/Users/justin/test/level-1/node-y.tar.gz"
  },
  {
    "hash": "fce57d4407e847c4c13cb2867d3f00f2aed4b5c569385d04765abe2fcae726bb",
    "path": "/Users/justin/test/level-1/install.dmg"
  }
]

This is just a basic example, in reality, its going to be thousands, even tens of thousands of objects long. I want to group the duplicates on hash, so basically sort by hash the fastest way possible, so quick sort. The result, then should look like:

[
  {
    "hash": "2e456c8de66a4ab6cf929d52bd6928b2d0096a8116891ade3dde9588c5f6b3c2",
    "path": "/Users/justin/test/logo_large.psd"
  },
  {
    "hash": "b1adffc1988b7339c7d4c59310fb3a64ce89e776a4924d492e819a08a7dce3fd",
    "path": "/Users/justin/test/level-1/level-1-1/music.mp3"
  },
  {
    "hash": "fce57d4407e847c4c13cb2867d3f00f2aed4b5c569385d04765abe2fcae726bb",
    "path": "/Users/justin/test/level-1/install.dmg"
  }, 
  {
     "hash": "fe5642d26d04cc7e7d47daa426da2a79e244bdcbae1594a12578f0d6fe03082e",
     "path": "/Users/justin/test/node-w.tar.gz"
   },
   {
     "hash": "fe5642d26d04cc7e7d47daa426da2a79e244bdcbae1594a12578f0d6fe03082e",
     "path": "/Users/justin/test/level-1/level-1-1/node-z.tar.gz"
   },
   {
     "hash": "fe5642d26d04cc7e7d47daa426da2a79e244bdcbae1594a12578f0d6fe03082e",
     "path": "/Users/justin/test/level-1/node-y.tar.gz"
   }
 ]
  • 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-05-27T03:19:09+00:00Added an answer on May 27, 2026 at 3:19 am

    The standard Javascript Array.sort() is pretty fast:

    myArray.sort(function(a,b) { 
        return a.hash == b.hash ? 0 : 
            a.hash > b.hash ? 1 : -1; 
    });
    

    Edit: As @Aaron notes, this is cleaner with .localeCompare:

    myArray.sort(function(a,b) { 
        return a.hash.localeCompare(b.hash);
    });
    

    If you’re just trying to find or group by duplicate hashes, though, you might want to collect in an object keyed to the hash:

    var hashes = {},
        groups = [],
        i, hash;
    for (i=0; i < myArray.length; i++) {
        hash = myArray[i].hash;
        if (hash in hashes) {
            hashes[hash].push(myArray[i]);
        } else {
            hashes[hash] = [myArray[i]];
        }
    }
    // now turn into an array
    for (hash in hashes) {
        if (hashes.hasOwnProperty(hash)) {
            groups.push(hashes[hash]);
        }
    }
    

    The groups array would now have a series of 1-to-n length arrays, each containing all objects with a particular hash.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Assuming I have the following I wish to unit test: class Foo: IAMethods, IBMethods
Assuming I have the following two JQuery functions - The first, which works: $(#myLink_931).click(function
Assuming I have the following strings: string str1 = Hello World!; string str2 =
Assuming you have the following XML: <?xml version=1.0 encoding=utf-8?> <content> <info> <media> <image> <info>
In a java app, assuming I have option of choosing the following comparison methods
Is there a cleaner way to do the following, assuming that I have a
I have some thread-related questions, assuming the following code. Please ignore the possible inefficiency
Assuming I have a tree structure UL --LI ---INPUT (checkbox) And I want to
Assuming I have the following delegate: public delegate int TestD(int p); Is there any
Assuming you have the following database table: create table Names ( Id INT IDENTITY

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.