Jump to content

How to convert this array to this


Recommended Posts

Hi guys. I am trying to convert this array to this other (or create a new)                          

                         I dont know this number (vars)

Stephany     |    9851

Franklin       |    3001

Lisa             |    9851

Dylan           |   9851

Ashley         |    3001

Jimmy         |     2115

Hilary          |     2115

Johnson     |      2115

Eno            |     1500

Gal            |      2115

Into==>

Stepanhy   |    Lisa    |   Dylan   |

Franklin     |   Ashley |

Jimmy      |  Hilary     | Johnson |   Gal

Eno          |                |               |

 

#include <Array.au3>

Global $aNamesID[10][2] = _
[["Stephany",9851] _
,["Franklin",3001] _
,["Lisa"    ,9851] _
,["Dylan"   ,9851] _
,["Ashley"  ,3001] _
,["Jimmy"   ,2115] _
,["Hilary"  ,2115] _
,["Johnson" ,2115] _
,["Eno"     ,1500] _
,["Gal"     ,2115]]

_ArrayDisplay($aNamesID)

 

Edited by GordonFreeman
Link to comment
Share on other sites

  • Moderators

Your question is a bit vague, but I am assuming you want to take the 2D array and create a 1D with just the names? Something like this?

#include <Array.au3>

Local $aFinal[0]
Global $aNamesID[10][2] = _
[["Stephany",9851] _
,["Franklin",3001] _
,["Lisa"    ,9851] _
,["Dylan"   ,9851] _
,["Ashley"  ,3001] _
,["Jimmy"   ,2115] _
,["Hilary"  ,2115] _
,["Johnson" ,2115] _
,["Eno"     ,1500] _
,["Gal"     ,2115]]

;_ArrayDisplay($aNamesID)

For $i = 0 To 9
    _ArrayAdd($aFinal, $aNamesID[$i][0])
Next

_ArrayDisplay($aFinal)

 

Or are you saying you want to break the names up into different columns in another 2D array?

Edited by JLogan3o13

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Your question is a bit vague, but I am assuming you want to take the 2D array and create a 1D with just the names? Something like this?

#include <Array.au3>

Local $aFinal[0]
Global $aNamesID[10][2] = _
[["Stephany",9851] _
,["Franklin",3001] _
,["Lisa"    ,9851] _
,["Dylan"   ,9851] _
,["Ashley"  ,3001] _
,["Jimmy"   ,2115] _
,["Hilary"  ,2115] _
,["Johnson" ,2115] _
,["Eno"     ,1500] _
,["Gal"     ,2115]]

;_ArrayDisplay($aNamesID)

For $i = 0 To 9
    _ArrayAdd($aFinal, $aNamesID[$i][0])
Next

_ArrayDisplay($aFinal)

 

Or are you saying you want to break the names up into different columns in another 2D array?

Yes, sorry. The number of columns will depend of most repeated id. In other words i want group every name with your ID. By example, Franklin and Ashley have the same ID. Franklin will be [X][0] and ashley will be [X][1]. Each "line" will reserved for each ID. Thanks in advance!

Link to comment
Share on other sites

Just for fun...

#include <Array.au3>

Global $aNamesID[10][2] = _
        [["Stephany", 9851] _
        , ["Franklin", 3001] _
        , ["Lisa", 9851] _
        , ["Dylan", 9851] _
        , ["Ashley", 3001] _
        , ["Jimmy", 2115] _
        , ["Hilary", 2115] _
        , ["Johnson", 2115] _
        , ["Eno", 1500] _
        , ["Gal", 2115]]

_ArrayDisplay($aNamesID)


Local $aNewArray[0][0]
Local $aFound = 0
Local $iFlagIndex = 0
local $iMaxIndex = 0
Local $c = 0
For $i = 0 To UBound($aNamesID) - 1
    $iMaxIndex = _ArrayMax($aNamesID, 1, Default, Default, 1)
    $aFound = _ArrayFindAll($aNamesID, $iMaxIndex, 0, 0, 0, 0, 1)
    ;_ArrayDisplay($aFound)
    If IsArray($aFound) Then
        ReDim $aNewArray[UBound($aNewArray, 1) + 1][UBound($aNewArray, 2)]
        If UBound($aNewArray, 2) < UBound($aFound) Then ReDim $aNewArray[UBound($aNewArray, 1)][UBound($aFound)]
        For $x = 0 To UBound($aFound) - 1
            $aNewArray[UBound($aNewArray, 1) - 1][$x] = $aNamesID[Int($aFound[$x])][0]
            $aNamesID[Int($aFound[$x])][1] = Null
        Next
        $iFlagIndex += UBound($aFound)

    EndIf

    If $iFlagIndex = UBound($aNamesID, 1) Then ExitLoop

Next

_ArrayDisplay($aNewArray)

Saludos

Edited by Danyfirex
Link to comment
Share on other sites

  • Moderators

Yes, sorry. The number of columns will depend of most repeated id. In other words i want group every name with your ID. By example, Franklin and Ashley have the same ID. Franklin will be [X][0] and ashley will be [X][1]. Each "line" will reserved for each ID. Thanks in advance!

This would have been helpful in your OP ;)

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Just for fun...

#include <Array.au3>

Global $aNamesID[10][2] = _
        [["Stephany", 9851] _
        , ["Franklin", 3001] _
        , ["Lisa", 9851] _
        , ["Dylan", 9851] _
        , ["Ashley", 3001] _
        , ["Jimmy", 2115] _
        , ["Hilary", 2115] _
        , ["Johnson", 2115] _
        , ["Eno", 1500] _
        , ["Gal", 2115]]

_ArrayDisplay($aNamesID)


Local $aNewArray[0][0]
Local $aFound = 0
Local $iFlagIndex = 0
local $iMaxIndex = 0
Local $c = 0
For $i = 0 To UBound($aNamesID) - 1
    $iMaxIndex = _ArrayMax($aNamesID, 1, Default, Default, 1)
    $aFound = _ArrayFindAll($aNamesID, $iMaxIndex, 0, 0, 0, 0, 1)
    ;_ArrayDisplay($aFound)
    If IsArray($aFound) Then
        ReDim $aNewArray[UBound($aNewArray, 1) + 1][UBound($aNewArray, 2)]
        If UBound($aNewArray, 2) < UBound($aFound) Then ReDim $aNewArray[UBound($aNewArray, 1)][UBound($aFound)]
        For $x = 0 To UBound($aFound) - 1
            $aNewArray[UBound($aNewArray, 1) - 1][$x] = $aNamesID[Int($aFound[$x])][0]
            $aNamesID[Int($aFound[$x])][1] = Null
        Next
        $iFlagIndex += UBound($aFound)

    EndIf

    If $iFlagIndex = UBound($aNamesID, 1) Then ExitLoop

Next

_ArrayDisplay($aNewArray)

Saludos

Thanks!

Link to comment
Share on other sites

Another way :

#include <Array.au3>

Local $aFinal[0]
Global $aNamesID[10][2] = _
[["Stephany",9851] _
,["Franklin",3001] _
,["Lisa"    ,9851] _
,["Dylan"   ,9851] _
,["Ashley"  ,3001] _
,["Jimmy"   ,2115] _
,["Hilary"  ,2115] _
,["Johnson" ,2115] _
,["Eno"     ,1500] _
,["Gal"     ,2115]]

ReDim $aNamesID[UBound($aNamesID)][UBound($aNamesID)]

_ArraySort($aNamesID, 0, 0, 0, 1)

Local $iIndex = 0, $iLastID = -1, $iCol = 1, $iMaxCol = 0

For $i = 0 To UBound($aNamesID) - 1
    If $aNamesID[$i][1] = $iLastID Then
        $iCol += 1
        $aNamesID[$iIndex][$iCol] = $aNamesID[$i][0]
        If $iCol > $iMaxCol Then $iMaxCol = $iCol
    Else
        If $i > 0 Then $iIndex += 1
        $iLastID = $aNamesID[$i][1]
        $aNamesID[$iIndex][1] = $aNamesID[$i][0]
        $aNamesID[$iIndex][0] = $iLastID
        $iCol = 1
    EndIf
Next

Redim $aNamesID[$iIndex + 1][$iMaxCol + 1]

_ArrayDisplay($aNamesID)

 

Link to comment
Share on other sites

Although not exactly what you asked for, I would go an array of arrays route...so global redims aren't required which will populate lots of blank values:

#include <Array.au3>
Global $aNamesID[10][2] = _
[["Stephany",9851] _
,["Franklin",3001] _
,["Lisa"    ,9851] _
,["Dylan"   ,9851] _
,["Ashley"  ,3001] _
,["Jimmy"   ,2115] _
,["Hilary"  ,2115] _
,["Johnson" ,2115] _
,["Eno"     ,1500] _
,["Gal"     ,2115]]

Local $aTemp[1] = [$aNamesID[0][0]]
Global $aNew[1][2] = [[$aNamesID[0][1],$aTemp]]

For $i = 1 To UBound($aNamesID)-1
    $iTemp = _ArraySearch($aNew,$aNamesID[$i][1],Default,Default,Default,Default,Default,0)
    If $iTemp >= 0 Then
        $aTemp = $aNew[$iTemp][1]
        _ArrayAdd($aTemp,$aNamesID[$i][0])
        $aNew[$iTemp][1] = $aTemp
    Else
        Local $aTemp[1]=[$aNamesID[$i][0]]
        ReDim $aNew[UBound($aNew)+1][2]
        $aNew[UBound($aNew)-1][0] = $aNamesID[$i][1]
        $aNew[UBound($aNew)-1][1] = $aTemp
    EndIf
Next

_ArrayDisplay($aNew)
For $i = 0 To UBound($aNew)
    _ArrayDisplay($aNew[$i][1])
Next

 

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...