5. 5
● Logic:
1. For each object from the
FlightOptions array, create one
output object inside the output array.
Requirement
5
6. 6
● Logic:
1. For each object from the
FlightOptions array, create one
output object inside the output array.
2. The AppliedTaxCode will contain the
value from the last Connection
object.
Requirement
6
7. 7
● Logic:
1. For each object from the
FlightOptions array, create one
output object inside the output array.
2. The AppliedTaxCode will contain the
value from the last Connection
object.
3. If the EndOfConnection field is true,
create a separate output object.
Requirement
7
8. 8
● Logic:
1. For each object from the
FlightOptions array, create one
output object inside the output array.
2. The AppliedTaxCode will contain the
value from the last Connection
object.
3. If the EndOfConnection field is true,
create a separate output object.
4. If there are EndOfConnection fields
that are true and this is not the last
object inside the Connections array,
create a new output object
containing all the false Connection
objects before this, and using this
last object’s TaxCode.
Requirement
8
9. 9
● Logic:
1. For each object from the
FlightOptions array, create one
output object inside the output array.
2. The AppliedTaxCode will contain the
value from the last Connection
object.
3. If the EndOfConnection field is true,
create a separate output object.
4. If there are EndOfConnection fields
that are true and this is not the last
object inside the Connections array,
create a new output object
containing all the false Connection
objects before this, and using this
last object’s TaxCode.
5. Each AppliedConnections object in
the output must have:
1. A hardcoded Type value
“Connection”.
Requirement
9
13. 13
2) Change all the EndOfConnection to true for the last Connection object from the Connections
array.
Building the Solution
14. 14
3) flatten the array of arrays to be just one array.
Building the Solution
15. 15
4) Parameters:
1. connectionsArray - Current connections array (this will have less values each time, until array is
empty).
2. indexAccumulatorArray - Array with the indexes that are being accumulated for the ”IndexValue”
field.
3. index - Actual index number for each connection being evaluated.
4. connectionsAccumulatorArray - Array that will keep the transformed objects (final output) – This is
what makes our function a tail function.
Building the Solution – Tail Recursive function
16. 16
Iteration 1:
Building the Solution – Tail Recursive function
connectionsArray (original array) indexAccumulatorArray
index
connectionsAccumulatorArray
thisConnection
EndOfConnection = false
Nothing is added to
connectionsAccumulatorArray
Next connection
indexAccumulatorArray should
contain this index
because
thisConnectionEndOfConnection
is false.
17. 17
Iteration 2:
Building the Solution – Tail Recursive function
connectionsArray (original array) indexAccumulatorArray
index
connectionsAccumulatorArray
thisConnection
EndOfConnection = true
Object is added to
connectionsAccumulatorArray
Next connection
indexAccumulatorArray should go
back to [ ] because
thisConnectionEndOfConnection
is true.
18. 18
Iteration 3:
Building the Solution – Tail Recursive function
connectionsArray (original array) indexAccumulatorArray
index
connectionsAccumulatorArray
thisConnection
EndOfConnection = true
Object is added to
connectionsAccumulatorArray
Next connection
indexAccumulatorArray should go
back to [ ] because
thisConnectionEndOfConnection
is true.
19. 19
Iteration 4:
Building the Solution – Tail Recursive function
connectionsArray (original array) indexAccumulatorArray
index
connectionsAccumulatorArray
thisConnection
EndOfConnection = true
Object is added to
connectionsAccumulatorArray
Next connection
indexAccumulatorArray should go
back to [ ] because
thisConnectionEndOfConnection
is true.
20. 20
Iteration 5:
Building the Solution – Tail Recursive function
connectionsArray (original array) indexAccumulatorArray
index
connectionsAccumulatorArray
thisConnection
EndOfConnection = false
Nothing is added to
connectionsAccumulatorArray
Next connection
indexAccumulatorArray should
contain this index
because
thisConnectionEndOfConnection
is false.
21. 21
Iteration 6:
Building the Solution – Tail Recursive function
connectionsArray (original array) indexAccumulatorArray
index
connectionsAccumulatorArray
thisConnection
EndOfConnection = false
Nothing is added to
connectionsAccumulatorArray
Next connection
indexAccumulatorArray should
contain this index
because
thisConnectionEndOfConnection
is false.
22. 22
Iteration 7:
Building the Solution – Tail Recursive function
connectionsArray (original array) indexAccumulatorArray
index
connectionsAccumulatorArray
thisConnection
EndOfConnection = true
Object is added to
connectionsAccumulatorArray
Next connection
indexAccumulatorArray should go
back to [ ] because
thisConnectionEndOfConnection
is true.
23. 23
Iteration 8:
Building the Solution – Tail Recursive function
connectionsArray (original array) indexAccumulatorArray
index
connectionsAccumulatorArray
thisConnection
EndOfConnection = true
Object is added to
connectionsAccumulatorArray
Next connection
indexAccumulatorArray should go
back to [ ] because
thisConnectionEndOfConnection
is true.
To be continued…