This is my JSON Data.
data: any = {
laneId: '0e8679b6-0138-44hj-a645-4738ca4fa0op',
totalLegs: 3,
totalOrders: 180,
laneLegs: [
{
legNo: 1,
startCity: 'Los Angeles',
startProvince: 'KY',
endCity: 'Los Angeles',
endProvince: 'KY',
totalOrders: 57,
},
{
legNo: 1,
startCity: 'Los Angeles',
startProvince: 'KY',
endCity: 'Washington',
endProvince: 'ON',
totalOrders: 10,
},
{
legNo: 1,
startCity: 'Los Angeles',
startProvince: 'KY',
endCity: 'Houston',
endProvince: 'ON',
totalOrders: 6,
},
{
legNo: 2,
startCity: 'Los Angeles',
startProvince: 'KY',
endCity: 'Houston',
endProvince: 'ON',
totalOrders: 34,
},
{
legNo: 2,
startCity: 'Los Angeles',
startProvince: 'KY',
endCity: 'Memphis',
endProvince: 'ON',
totalOrders: 21,
},
{
legNo: 2,
startCity: 'Los Angeles',
startProvince: 'KY',
endCity: 'Chicago',
endProvince: 'ON',
totalOrders: 1,
},
{
legNo: 2,
startCity: 'Washington',
startProvince: 'ON',
endCity: 'Boise',
endProvince: 'ON',
totalOrders: 4,
},
{
legNo: 2,
startCity: 'Washington',
startProvince: 'ON',
endCity: 'Memphis',
endProvince: 'ON',
totalOrders: 4,
},
{
legNo: 2,
startCity: 'Washington',
startProvince: 'ON',
endCity: 'Houston',
endProvince: 'ON',
totalOrders: 2,
},
{
legNo: 2,
startCity: 'Houston',
startProvince: 'ON',
endCity: 'Boise',
endProvince: 'ON',
totalOrders: 4,
},
{
legNo: 2,
startCity: 'Houston',
startProvince: 'ON',
endCity: 'Memphis',
endProvince: 'ON',
totalOrders: 2,
},
{
legNo: 3,
startCity: 'Houston',
startProvince: 'ON',
endCity: 'Boston',
endProvince: 'ON',
totalOrders: 36,
},
{
legNo: 3,
startCity: 'Memphis',
startProvince: 'ON',
endCity: 'Boston',
endProvince: 'ON',
totalOrders: 35,
},
{
legNo: 3,
startCity: 'Chicago',
startProvince: 'ON',
endCity: 'Boston',
endProvince: 'ON',
totalOrders: 1,
},
{
legNo: 3,
startCity: 'Boise',
startProvince: 'ON',
endCity: 'Boston',
endProvince: 'ON',
totalOrders: 8,
},
],
};
I tried many approaches. But all are available here.
It works like legNo.
Leg 1 Value:
Start City: Los Angeles, End City: Los Angeles
Start City: Los Angeles, End City: Washington
Start City: Los Angeles, End City: Houston
Here Leg 1 Output is:
[Los Angeles, Los Angeles]
[Los Angeles, Washington]
[Los Angeles, Houston]
Leg 2 Value:
Leg 2 Output depends on Leg 1 Output:
Start City: Los Angeles, End City: Houston
Start City: Los Angeles, End City: Memphis
Start City: Los Angeles, End City: Chicago
Start City: Washington, End City: Boise
Start City: Washington, End City: Memphis
Start City: Washington, End City: Houston
Start City: Houston, End City: Boise
Start City: Houston, End City: Memphis
Here Leg 2 Output is:
[Los Angeles, Los Angeles, Houston] //Here checked 2 index if Los Angeles available then push Houston on last index
[Los Angeles, Los Angeles, Memphis] //Here copy array index and add Memphis on last index
[Los Angeles, Los Angeles, Chicago] //Here copy array index and add Chicago on last index
[Los Angeles, Washington, Boise]
[Los Angeles, Washington, Memphis]
[Los Angeles, Washington, Houston]
[Los Angeles, Houston, Boise]
[Los Angeles, Houston, Memphis]
Leg 3 Value:
Leg 3 Output depends on Leg 1 and Leg 2 Output:
Start City: Houston, End City: Boston
Start City: Memphis, End City: Boston
Start City: Chicago, End City: Boston
Start City: Boise, End City: Boston
Here Leg 2 Output is:
[Los Angeles, Los Angeles, Houston, Boston] //Here checked 3 index if Houston available then push all place Boston
[Los Angeles, Los Angeles, Memphis, Boston] //Here checked 3 index if Memphis available then push all place Boston
[Los Angeles, Los Angeles, Chicago, Boston]
[Los Angeles, Washington, Boise, Boston]
[Los Angeles, Washington, Memphis, Boston] //Here checked 3 index if Memphis available then push all place Boston
[Los Angeles, Washington, Houston, Boston] //Here checked 3 index if Houston available then push all place Boston
[Los Angeles, Houston, Boise, Boston]
[Los Angeles, Houston, Memphis, Boston]
I need this for my final Output:
[Los Angeles, Los Angeles, Houston, Boston]
[Los Angeles, Los Angeles, Memphis, Boston]
[Los Angeles, Los Angeles, Chicago, Boston]
[Los Angeles, Washington, Boise, Boston]
[Los Angeles, Washington, Memphis, Boston]
[Los Angeles, Washington, Houston, Boston]
[Los Angeles, Houston, Boise, Boston]
[Los Angeles, Houston, Memphis, Boston]