Sign in to follow this  
Followers 0
noknown

Array roll up

5 posts in this topic

Hi All!

Does anybody know about ready function which can roll an array with grouping and summing values.

Example 2D array BEFORE:

Name Orders

John 25

Smith 30

Adams 20

John 10

Adams 30

Example 2D array AFTER:

Name Orders

John 35

Smith 30

Adams 50

I could write my own, but if somewhere is ready to function - what a shame to spend time.

Sorry, if this question is very simple. I'm beginning programmer.

And sorry for my english.

Thanks for for answers (if they will)

Share this post


Link to post
Share on other sites



I've never seen a UDF specifically for that (not saying there isnt one), but I'm sure there will be a combination of UDFs you could use to achieve it.

My personal thought are that it would take you longer to learn the ready functions and implement them, than it would to make your own custom function. And you would learn more writing your own.


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

I've never seen a UDF specifically for that (not saying there isnt one), but I'm sure there will be a combination of UDFs you could use to achieve it.

My personal thought are that it would take you longer to learn the ready functions and implement them, than it would to make your own custom function. And you would learn more writing your own.

Thank u!

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

It makes life easier to process arrays in reverse order when you're likely to be doing deletions to the array.

Something like:

#include <Array.au3>
Global $array[6][2] = [["John",25],["Smith",30],["Adams",20],["John",10],["Adams",30],["John",5]]

_ArrayDisplay($array)

For $x = UBound($array) - 1 to 1 Step -1
    For $y = $x - 1 to 0 Step -1
        If $array[$x][0] = $array[$y][0] Then
            $array[$y][1] += $array[$x][1]
            _ArrayDelete($array, $x)
            ExitLoop
        EndIf
    Next
Next

_ArrayDisplay($array)
Edited by Spiff59

Share this post


Link to post
Share on other sites

It makes life easier to process arrays in reverse order when you're likely to be doing deletions to the array.

Thank u very much!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0