Forum Academy Marketplace Showcase Pricing Features

Add individual items in two lists together

Hi there. Sorry if this has been raised before.

I have two lists of items and want to add them together without having to process each addition manually. So for instance if my lists were

List one: 1 , 2 , 3 , 4 , 5
List two: 5 , 6 , 7 , 8 , 9

The outcome would be: 6 , 8 , 10 , 12 , 14

This might be easy but it’s got me stumped.

Hey @jof,

I’m stumped on how this might be done in native Bubble, but here again we can use the Expression element from the absolutely must have free Toolbox plugin. The result will be a Bubble list of numbers:

Here’s the code for copy/paste (just insert your arrays of numbers):

var array1 = [],
    array2 = [],
    l = Math.max(array1.length, array2.length);

var result = Array(l);
for(var i=0; i<l; ++i) result[i] = (array1[i] || 0) + (array2[i] || 0);

result;

If nobody else replies with a simpler idea, give it a go!

–Ken



Looking to accelerate your app development?

Development of Advanced Apps at https://uniqueideas.com or schedule a free intro session :gift:

Ken Truesdale
LinkedIn

3 Likes

That’s perfect worked straight away! You’re brilliant buddy.

1 Like

This just saved me a huge headache as I am finalizing an analytics chart…needed to take the mobile views and desktop views to show a total in a graph and this sorted it right out.

Thanks for posting.

could anyone rewrite this for multiplying two lists together instead of adding? Thanks

Have you tried changing the plus sign (+) to a multiply sign (*)??