Created
August 17, 2021 07:40
-
-
Save encikpulasan/45e8783385e8255a516f4d557f46799f to your computer and use it in GitHub Desktop.
Exploring recursive implementation from for loop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Loop through RecentTransaction to perform specific function | |
void searchTransaction(Transaction transaction, void Function(int i, int j) function) { | |
for (var i = 0; i < recentTransactions!.dailyTransactions!.length; i++) { | |
DailyTransaction dailyTransaction = recentTransactions!.dailyTransactions![i]; | |
for (var j = 0; j < dailyTransaction.transactions!.length; j++) { | |
Transaction trx = dailyTransaction.transactions![j]; | |
if (trx.id == transaction.id) { | |
function(i, j); | |
} | |
} | |
} | |
} | |
/// Recursive through DailyTransaction to find and perform function | |
void findIndex(int id, List<DailyTransaction> daily, void Function(int i, int y) function, {int i = 0, int y = 0}) { | |
if (id == daily[i].transactions![y].id) { | |
function(i, y); | |
} else if (y + 1 == daily[i].transactions!.length) { | |
if (i + 1 < daily.length) { | |
findIndex(id, daily, (i, y) => function(i, y), i: i + 1, y: 0); | |
} | |
} else { | |
findIndex(id, daily, (i, y) => function(i, y), i: i, y: y + 1); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment