I am storing numeric values in multiple comma delineated lists. I would like to be able to add up the values so that I can also display an aggregated list of values. Not sure how to approach doing this.
i.e.
List:
L1: 1,2,3,4
L2: 1,2,3,4
L3: 1,2,3,4
Aggregated Output:
A1: 3,6,9,12
** I have N number of Lists,
** Each list will have the same number of values
A bit of custom javascript might be the best option here as handling equations, especially on lists that need to be parsed, isn’t always the easiest in Bubble. You will need the Toolbox plugin installed. I made a quick video showing how I solved this and here is the javascript:
function aggregateLists(lists) {
// Parse the input lists into arrays of numbers
let parsedLists = lists.map(list => list.split(',').map(Number));
// Get list length
let listLength = parsedLists[0].length;
// Initialize an array to store the aggregated values
let aggregated = new Array(listLength).fill(0);
// Sum the corresponding elements of the arrays
parsedLists.forEach(list => {
list.forEach((value, index) => {
aggregated[index] += value;
});
});
// Join the aggregated values into a comma-delimited string
let aggregatedString = aggregated.join(',');
return aggregatedString;
}
let lists = [INSERT YOUR LIST HERE];
let aggregatedOutput = aggregateLists(lists);
bubble_fn_sum(aggregatedOutput);