Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Joining two arrays with lookup

function join(lookupTable, mainTable, lookupKey, mainKey, select) {
    var l = lookupTable.length,
        m = mainTable.length,
        lookupIndex = [],
        output = [];
    for (var i = 0; i < l; i++) { // loop through l items
        var row = lookupTable[i];
        lookupIndex[row[lookupKey]] = row; // create an index for lookup table
    }
    for (var j = 0; j < m; j++) { // loop through m items
        var y = mainTable[j];
        var x = lookupIndex[y[mainKey]]; // get corresponding row from lookupTable
        output.push(select(y, x)); // select only the columns you need
    }
    return output;
};
Comment

PREVIOUS NEXT
Code Example
Javascript :: random color javascript 
Javascript :: element non empty jquer y check 
Javascript :: Star Wars Celebration 
Javascript :: js set height of element 
Javascript :: calculate percentage in javascript 
Javascript :: compare strings to multiple strings javascript 
Javascript :: react-popper-2 
Javascript :: JSON: remember you can use a value that comes later 
Javascript :: how to use graph api with react native 
Javascript :: JS in JSX. Whenever you need to add some JS, just put it inside curly braces {} 
Javascript :: s3 getobject not getting large json object 
Javascript :: using condition how to disable radio button in angular 
Javascript :: Backbone Initialize vs Render 
Javascript :: how can we find location by using date in javascript 
Javascript :: save slug on schema pre save in node js 
Javascript :: react native leaflet 
Javascript :: broken image 
Javascript :: firebase database TIMESTAMP 
Javascript :: hide header on button click in react native 
Javascript :: how to sum up the first 2 elements in an array javascript 
Javascript :: move_uploaded_file equivalent in js 
Javascript :: add image to center in canvas 
Javascript :: clear timers nodejs 
Javascript :: express roteamento 
Javascript :: load content on user language in javascript 
Javascript :: js proxy track nested object 
Javascript :: how to set maxLength of input type number in react 
Javascript :: sanitize html before storing to db in js 
Javascript :: javascript axios response.data.pipe not a function 
Javascript :: angularjs how to get a response from a post request 
ADD CONTENT
Topic
Content
Source link
Name
3+9 =