Hey @hello.plannwin, thanks for the kind comments. So, I’m not sure exactly what it is you ultimately want to do (because you don’t say), but as for the case of dividing one list of numbers by another list of numbers, you can do this.
However, note that the natural outcome of taking List 1 and dividing each element by every element in List 2, would be an array of arrays (as Bubble would have it, a List of Lists), and Bubble does not have a simple data type that supports this. (Well, we could create a Thing that has an array of arrays on it, but this cannot exist in the page and so is not helpful to us here.)
Example: If list 1 has 10 values in it and list 2 has 10 values in it and we do an array-wise division like you’re trying to do you’d end up with a 10 x 10 array of 100 values, right?
We can’t export a 2-dimensional array like this to Bubble, but we can flatten it into a one-dimensional array. More to the point, we can build the answer that way. (We just need to understand that our vector of 100 represents 10 chunks of 10 divisions, yeah?)
All we can return to Bubble from List Shifter is a one-dimensional array of simple data types. Lists are one-dimensional arrays. For example, the numbers one through ten: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
. This would be a List of type number in Bubble parlance.
OK, so how do we do your operation in List Shifter. Here’s an example page where I have 2 List Shifters, each holding a list of numbers. For clarity, I use a third List Shifter to do the division computation using PROCESS List. But note that we could have done this without needing a third List Shifter.
That third List Shifter (blue one) just takes the second List Shifter’s list as its “list to shift”.
The PROCESS List step is set up like this:
We’ll iterate over its list (which is the numbers from LS 2). So we import the values from LS 1 using the LS Type List Constant (way down in the dialog). I’ve activated DEBUG mode so, in our console, we can see what’s happening:
And then back to the top, here are our steps: In step 1 we do the listwise division. As I think you know, if one of our operands is a List, we’ll actually do the operation on all of the elements in that list, yielding us an array. So, if you open your console and click the DIVIDE button, you’ll see, for the first iteration, we get the values for LS 1 array divided by the first value in LS 2:
Now, what do we do with the result of Step 1 (RS1)?
Instead of pushing this to Processed Result, we’ll instead use the Custom List. Custom List is an internal value that’s a little like Processed List, but it is only published when we say so.
And what we’re going to do in Step 2 is take the Custom List (which will start out as an empty array) and CONCATENATE RS1 (the result of step 1) on to it. Like this:
This says, whatever Custom List is right now, take the array from RS1 and append it. So in the first run through, Custom List is
[]
and RS1 is
[0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5]
and we get
[0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5]
as the result of step 2 (RS2).
And then, in this second step, we SET the value of Custom List to be this result (see circled “yes”).
There are no more steps (but a little more setup) that I’ll discuss below. Now on our second iteration, what will happen is that the values in LS 1 will be divided by the second value in LS 2, and in my example this yields [0.25, 0.5, 0.75, 1, 1.25, 1.5, 1.75, 2, 2.25, 2.5]
:
Then the second step concatenates that result onto Custom List (which already has 10 numbers in it), and now it’s the first 20 results.
This continues until we have walked through all of the values in LS 2. Here’s what we have in our final result (an array of 100 values):
NOW, as I mentioned, Custom List is only published when we say so, so down at the bottom of PROCESS List dialog, I set Publish Custom List (which happens at the very end of the iteration cycle):
And now my answer appears at LS Compute’s Custom List output.
Additionally Custom List is persistent and executing PROCESS List does not automatically clear Custom List. So, in this case, we would want to ensure Custom List is clear before we do PROCESS List and we can do that with the SET Custom List action:
We do that by setting Custom List to empty and, by also setting Publish Custom List to yes, we also clear the values present at the Custom List output.
Inspect the edit mode for the example page to see all of this in place.