Im passing an array of arrays to a function. I want to:
- filter each array for unique values
- concatenate the filtered arrays into a single array
- coerce the array into a Set, therefore creating a single iterable object of unique values.
I can't seem to scope the variables within/out of function so that it allows me to use the function with any size array of arrays. I don't have any affection for anything but the outcome - a single iterable object of the uniques values amongst the array of arrays.
Pseudo code:
function getDataForHistogram(shipments, groupKeys) {
console.log('@getDataForHistogram');
let uniqueArry = [];
groupKeys.forEach(groupKey => {
uniqueArry.concat(shipments.reduce((accumulator, element) => {. //pseudo, I know concat returns an array
if ((accumulator.indexOf(Math.ceil(element[groupKey])) < 0)) {
accumulator.push(Math.ceil(element[groupKey]));
}
return accumulator;
},[])
})
let uniqueSet = new Set(...uniqueArry);
let range = {
min: Math.min(uniqueSet),
max: Math.max(uniqueSet)
};
console.log(uniqueSet);
console.log(range.min, range.max);
}
I'm flummoxed... The only alternative way that I have thought of is to count the number of arrays and iterate over each three recursively.