financialTransactions = [ "#2 -> John -Withdrawal- ~ $756.22", "#5 -> Cherry +Deposit+ ~ $4,332.54", "#1 -> Lily +Deposit+ ~ $375.66", "#3 -> Noah -Withdrawal- ~ $5,244.00", "#4 -> Slice +Deposit+ ~ $2,305.20" ]
I am trying to get it like this.
financialTransactions[0] = "#1 -> Janira +Deposit+ ~ $375.66" financialTransactions[1] = "#2 -> John -Withdrawal- ~ $756.22" financialTransactions[2] = "#3 -> Noah -Withdrawal- ~ $5,244.00" financialTransactions[3] = "#4 -> Slice +Deposit+ ~ $2,305.20" financialTransactions[4] = "#5 -> Cherry +Deposit+ ~ $4,332.54"
The way I have been thinking of solving the problem is to first make a copy. Then scan each member in the array for its second character then if that character is not equal to the index value + 1 then it is not in its correct spot. What I would then do is replace whatever is in there with the appropriate transaction that has the corresponding index value with the second character.
Here is what I have so far but being new to this I keep getting stuck on how to properly make this work.
financialTransactions = [ "#2 -> John -Withdrawal- ~ $756.22", "#5 -> Cherry +Deposit+ ~ $4,332.54", "#1 -> Janira +Deposit+ ~ $375.66", "#3 -> Noah -Withdrawal- ~ $5,244.00", "#4 -> Slice +Deposit+ ~ $2,305.20" ] puts("Original Transactions: ") puts(financialTransactions) #Variables idx = 0 organized = false done = false copyFinancialTransactions = [] falses = [] #Make a Copy of original - 0 < while idx < financialTransactions.length copyFinancialTransactions.push(financialTransactions[idx]) idx = idx + 1 end idx = 0 while idx < financialTransactions.length falses.push(false) idx = idx + 1 end idx = 0 while done == false transactionNumber = financialTransactions[idx] # not really needed just converted to a string so I can take the second character values -> check value #puts(transactionNumber) if transactionNumber[idx].to_i != idx + 1 #copy correct to original ¤t idx = 0(1) financialTransactions = copyFinancialTransactions[idx] end idx = idx + 1 end idx = 0 puts("Copy of the Original") puts(copyFinancialTransactions) #testing an array full of falses puts(falses)