[Solved] complex array merge using nested loop


As discussed in chat, here is a javascript example that builds what you asked for:

var tabs = [{"uId":"2","tabId":1,"tabName":"Main","points":"10","active":"true"},{"uId":"3","tabId":2,"tabName":"Photography","points":"20","active":""}];

var tasks = [{"taskId":3,"taskName":"Sing Sing Gem","priorty":3,"date":"2014-04-25","done":0,"tabId":1,"uId":"2"},{"taskId":4,"taskName":"Shooting","priorty":4,"date":"2014-04-25","done":0,"tabId":2,"uId":"3"}];

var uidSet = {};

var UIDSortFunction = function(a,b){
    uidSet[a.uId] = 1;
    uidSet[b.uId] = 1;
    return a.uId - b.uId;
};
tabs.sort(UIDSortFunction);
tasks.sort(UIDSortFunction);

var endResult = [];

var i, j, tabsLen = tabs.length, tasksLen = tasks.length, k = 0;


for(var key in uidSet)
{
    if(uidSet.hasOwnProperty(key))
    {
        endResult.push({
            uId : key,
            tabs:[],
            tasks:[]
        });
        for(i = 0; i < tabsLen; ++i)
        {
            if(tabs[i].uId === key)
                endResult[k].tabs.push({
                    tabId:tabs[i].tabId,
                    tabName: tabs[i].tabName,
                    points: tabs[i].points
                });
        }
        for(j = 0; j < tasksLen; ++j)
        {
            if(tasks[j].uId === key)
                endResult[k].tasks.push({
                    uId: tasks[j].uId,
                    tabId:tasks[j].tabId,
                    taskName: tasks[j].taskName
                });
        }
        ++k;
    }
}

console.log(endResult);

http://jsfiddle.net/fnf33/2/

solved complex array merge using nested loop