const join = (leftTable, rightTable, direction) => {
let tableOne;
let tableTwo;
if (direction.toLowerCase() === 'left') {
tableOne = leftTable;
tableTwo = rightTable;
} else if (direction.toLowerCase() === 'right') {
tableOne = rightTable;
tableTwo = leftTable;
} else { throw 'error, invalid join direction'; }
const results = [];
for (let i = 0; i < tableOne.buckets.length; i++) {
const row = [];
if (tableOne.buckets[i]) {
const key = (Object.keys(tableOne.buckets[i].head.value)[0]);
const value = (tableOne.buckets[i].head.value[key]);
row[row.length] = key;
row[row.length] = value;
if (tableTwo.contains(key)) {
row[row.length] = tableTwo.get(key);
}
else { row[row.length] = null; }
results[results.length] = row;
}
}
return results;
};