Thursday, June 20, 2013

O(n) JavaScript Unique Array


    
function arrayUnique(a) {
    var n = 0,
        o = {},
        a = [];
   
    for (;n<aRows.length;n++) { 
        if (!(aRows[n].id in o)) {
            o[aRows[n].id] = 1;
            a.push(aRows[n].id);
        }
    }
    return a;
}
    

No comments:

Post a Comment