Need a help of filtering and sum numbers

Hello good people, I am building a app. I have a custom state called listOfNumbers on an element called container. I am storing some numbers on that custom state (listOfNumbers) (e.g: container > listOfNumber = [1,2,45,6,12,6]). I want to display the sum of the numbers found between 1 and 7 or any other specified range. How can I do it? it means I want first to fielter numbers that fall in the range and then I want to sum those numbers. I want then to display that sum on the page. Everything is local there is no database involved. How can I do it?

Take the list of number…

Apply a filter… where the constraints are this number ≥ 1 and this number ≤ 7

The simply sum the filtered list, using the :sum operator.


Be aware that doing this will remove any duplicate numbers from the list… which will completely change the resulting sum.

I didn’t think we’d be able to filter a list of numbers because we can’t sort a list of numbers. Just tested this out and nice to see we can filter the list of numbers.

You can also sort a list of numbers (just add :sort to the list of numbers)

1 Like

Thanks @adamhholmes really works fine. :pray: Thanks for the quick help.

1 Like

This topic was automatically closed after 70 days. New replies are no longer allowed.