idea-toolbox
Advanced tools
Comparing version 0.6.0 to 0.7.0
28
index.js
@@ -27,3 +27,3 @@ 'use strict'; | ||
// OTHER | ||
ISODateToItalianFormat, cleanStr | ||
ISODateToItalianFormat, cleanStr, joinArraysOnKeys | ||
} | ||
@@ -313,1 +313,27 @@ | ||
} | ||
/** | ||
* Join two arrays by a common column, selecting which data to extract. | ||
* @param {Array<any>} mainTable the main array | ||
* @param {Array<any>} lookupTable the lookup array | ||
* @param {string} mainKey mainTable's column for the join condition | ||
* @param {string} lookupKey lookupTable's column for the join condition | ||
* @param {(attrMainTable, attrLookupTable) => Array<any>} selectFunction defines which attributes we want to retain in the joined array | ||
* @return {Array<any>} the joined array | ||
*/ | ||
function joinArraysOnKeys(mainTable, lookupTable, mainKey, lookupKey, selectFunction) { | ||
let l = lookupTable.length; | ||
let m = mainTable.length; | ||
let lookupIndex = []; | ||
let output = []; | ||
for(let i = 0; i < l; i++) { // loop through l items | ||
let row = lookupTable[i]; | ||
lookupIndex[row[lookupKey]] = row; // create an index for lookup table | ||
} | ||
for(let j = 0; j < m; j++) { // loop through m items | ||
let y = mainTable[j]; | ||
let x = lookupIndex[y[mainKey]]; // get corresponding row from lookupTable | ||
output.push(selectFunction(y, x)); // select only the columns you need | ||
} | ||
return output; | ||
} |
{ | ||
"name": "idea-toolbox", | ||
"version": "0.6.0", | ||
"version": "0.7.0", | ||
"description": "IDEA's utility functions", | ||
@@ -5,0 +5,0 @@ "engines": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16599
344