fork(2) download
  1. var districts = {
  2. "district": [{
  3. "ration": 4,
  4. "states": [{
  5. "name": "Louisiana",
  6. "population": 42383,
  7. "cities": [{
  8. "name": "Cavalero"
  9. }]
  10. }]
  11. }, {
  12. "ration": 1,
  13. "states": [{
  14. "name": "Colorado",
  15. "population": 980,
  16. "cities": []
  17. }, {
  18. "name": "Arkansas",
  19. "population": 58998,
  20. "cities": []
  21. }, {
  22. "name": "Illinois",
  23. "population": 59333,
  24. "cities": [{
  25. "name": "Kenwood"
  26. }]
  27. }]
  28. }, {
  29. "ration": 2,
  30. "states": [{
  31. "name": "Washington",
  32. "population": 83984,
  33. "cities": [{
  34. "name": "Conestoga"
  35. }, {
  36. "name": "Whitehaven"
  37. }, {
  38. "name": "Dellview"
  39. }]
  40. }, {
  41. "name": "West Virginia",
  42. "population": 38034,
  43. "cities": []
  44. }]
  45. }]
  46. };
  47. var i, district, j, states, k, cities;
  48. for (i = 0; i < districts.district.length; i++) {
  49. district = districts.district[i];
  50. print(i + 1, ". District", i + 1, "consists of following states", "--- ration", district.ration);
  51. for (j = 0; j < district.states.length; j++) {
  52. states = district.states[j];
  53. var said = (states.cities.length > 0) ? ("consists of following cities") : ("");
  54. print(i + 1, ".", j + 1, states.name, said, "--- population", states.population);
  55. for (k = 0; k < states.cities.length; k++) {
  56. cities = states.cities[k];
  57. print(" ", i + 1, ".", j + 1, ".", k + 1, cities.name);
  58. }
  59. }
  60. }
Success #stdin #stdout 0.02s 10736KB
stdin
Standard input is empty
stdout
1 . District 1 consists of following states --- ration 4
1 . 1 Louisiana consists of following cities --- population 42383
      1 . 1 . 1 Cavalero
2 . District 2 consists of following states --- ration 1
2 . 1 Colorado  --- population 980
2 . 2 Arkansas  --- population 58998
2 . 3 Illinois consists of following cities --- population 59333
      2 . 3 . 1 Kenwood
3 . District 3 consists of following states --- ration 2
3 . 1 Washington consists of following cities --- population 83984
      3 . 1 . 1 Conestoga
      3 . 1 . 2 Whitehaven
      3 . 1 . 3 Dellview
3 . 2 West Virginia  --- population 38034