use lodash javascript to full join two-dimensional array -


i have 2 two-dimensional array.

var arr1=[[1,20],[2,30]]; var arr2=[[2,40],[3,50]]; 

this expected output:

[[1,20,null],[2,30,40],[3,null,50]] 

it full join of 2 data frames. logic similar pseudo code:

df1.join(df2, df1[col_1] == df2[col_1], 'full') 

but case two-dimensional array. can lodash this? if not, how in vanilla javascript?

well, lodash can't this, can:

function flatten2d(arr1, arr2) {   const o1 = _.frompairs(arr1);   const o2 = _.frompairs(arr2);   const result = [];    _.foreach(o1, (v, k) => {     const v2 = o2[k] || null;     result.push([k|0, v, v2]);     delete o2[k];   });    _.foreach(o2, (v, k) => {     const v1 = o1[k] || null;     result.push([k|0, v1, v]);   });    return result; } 

testing:

flatten2d([[1,20],[2,30]], [[2,40],[3,50]]) 

result:

[[1,20,null], [2,30,40], [3,null,50]] 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -