473,396 Members | 1,940 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Merging and Sorting many lists into one [JavaScript].

135 100+
Guy's,

I'm rewriting a particular function and just need some guidance in understanding this function. I would be greatful if someone can explain each line to me:

function getMergedGroups() {
var mergedGroups = new Array();
for (var i in groups ) {

if (!(i == 'National Projects')) {
merge_loop: for (var j in groups[i]) {
for (var k in mergedGroups ) {
if ( j == k ) {

for ( m = 0;
m < groups[i][j].length; m++) {

mergedGroups[k][mergedGroups[k].length] = groups[i][j][m];
}
Jun 21 '07 #1
7 1178
rnd me
427 Expert 256MB
Guy's,

I'm rewriting a particular function and just need some guidance in understanding this function. I would be greatful if someone can explain each line to me:

function getMergedGroups() {
var mergedGroups = new Array(); //create a new list to hold combinded content.
for (var i in groups ) { //examine every index of existing array groups.

if (!(i == 'National Projects')) { //if not a nationalProducts main entry, add the sub group from groups to the new array.
merge_loop: for (var j in groups[i]) {
for (var k in mergedGroups ) {
if ( j == k ) {

for ( m = 0;
m < groups[i][j].length; m++) {

mergedGroups[k][mergedGroups[k].length] = groups[i][j][m]; //add each property of the orig subgroup after the last known combined list.
}


i commented the original above.
Jun 21 '07 #2
patelxxx
135 100+
Thank you very much that was very useful however I need to add a line/code in the code above to 'ACTUALLY' exclude 'National Projects' from the final array.

I don't want 'National Projects' to be included in the combined list, how can this be done.

Thanks in advance.

Ravi
Jun 26 '07 #3
acoder
16,027 Expert Mod 8TB
Do you get any errors in the code?

Expand|Select|Wrap|Line Numbers
  1. if (i != 'National Projects') {
Jun 26 '07 #4
patelxxx
135 100+
no errors, I added that line for debugging purposes.
Jun 27 '07 #5
acoder
16,027 Expert Mod 8TB
Can you give some sample data? I'm assuming that you're using a 3-dimensional array called groups.
Jun 28 '07 #6
patelxxx
135 100+
Thank you Acoder I've resolved this now.
Jul 4 '07 #7
acoder
16,027 Expert Mod 8TB
Glad you got it working. What was your solution?
Jul 4 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: Philippe C. Martin | last post by:
Hi, I'm looking for an easy algorithm - maybe Python can help: I start with X lists which intial sort is based on list #1. I want to reverse sort list #1 and have all other lists sorted...
2
by: Kakarot | last post by:
I'm gona be very honest here, I suck at programming, *especially* at C++. It's funny because I actually like the idea of programming ... normally what I like I'm atleast decent at. But C++ is a...
4
by: John Bullock | last post by:
Hello, I am at wit's end with an array sorting problem. I have a simple table-sorting function which must, at times, sort on columns that include entries with nothing but a space (@nbsp;). I...
24
by: Lasse Vågsæther Karlsen | last post by:
I need to merge several sources of values into one stream of values. All of the sources are sorted already and I need to retrieve the values from them all in sorted order. In other words: s1 = ...
4
by: FBM | last post by:
Hi, I am working on a program that simulates one of the elements of ATM. The simulation stores events which occurs every some milliseconds for a certain amount of time. Every time that an event...
16
by: Kittyhawk | last post by:
I would like to sort an Arraylist of objects on multiple properties. For instance, I have a Sort Index property and an ID property (both integers). So, the results of my sort would look like this:...
1
by: jmdolinger | last post by:
Hi all, I'm a newbie to Atlas (and recently ASP.NET) after coming from a long Java background, also have done quite a bit with an Ajax.NET/ASP.NET 1.1 project, but it was basically all...
20
by: martin-g | last post by:
Hi. Mostly I program in C++, and I'm not fluent in C# and .NET. In my last project I began to use LinkedList<and suddenly noticed that can't find a way to sort it. Does it mean I must implement...
8
by: DierkErdmann | last post by:
Hi ! I know that this topic has been discussed in the past, but I could not find a working solution for my problem: sorting (lists of) strings containing special characters like "ä", "ü",......
6
by: Osiris | last post by:
I have a *VAST* database of 10's of millions records. THere are two kinds of records in it, A an B. An A-record may be referencing B records. B-records should be referenced by one or more...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.