N
N
nelolka2018-01-09 15:55:10
JavaScript
nelolka, 2018-01-09 15:55:10

How to make a 2D array look like a tree?

I have this two dimensional array:

[
["1 сезон", "1 серия", "Лостфилм", "cyx793so9kodfhdwiktl0r6b/212164"],
["1 сезон", "2 серия", "Kinogo", "cyx793so9kodfhdwiktl0r6b/252865"],
["1 сезон", "2 серия", "Амедиа", "cyx793so9kodfhdwiktl0r6b/252865"],
["1 сезон", "3 серия", "Лостфилм", "cyx793so9kodfhdwiktl0r6b/264972"],
["2 сезон", "1 серия", "Лостфилм", "cyx793so9kodfhdwiktl0r6b/212164"],
["2 сезон", "2 серия", "Kinogo", "cyx793so9kodfhdwiktl0r6b/252865"],
["3 сезон", "1 серия", "Kinogo", "cyx793so9kodfhdwiktl0r6b/264972"]
]

You need to create a dependency tree for easy access and information. There should be several drop-down lists, the user selects the season in the first list, then the series and version.
The main thing is to turn this array into a tree-like array, where each season has several episodes, and each episode has (possibly) several versions. The last element of the array is a reference to the series, it does not participate in the selection.
The third day I'm breaking my head, how to do it right.
UPD: You need to write a script that will do this automatically with the input array.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2018-01-09
@nelolka

{
  "1 сезон": {
    "1 серия": {
      "Лостфилм": "cyx793so9kodfhdwiktl0r6b/212164"
    },
    "2 серия": {
      "Kinogo": "cyx793so9kodfhdwiktl0r6b/252865",
      "Амедиа": "cyx793so9kodfhdwiktl0r6b/252865"
    },
    "3 серия": {
      "Лостфилм": "cyx793so9kodfhdwiktl0r6b/264972"
    }
  },
  "2 сезон": {
    "1 серия": {
      "Лостфилм": "cyx793so9kodfhdwiktl0r6b/212164"
    },
    "2 серия": {
      "Kinogo": "cyx793so9kodfhdwiktl0r6b/252865"
    }
  },
  "3 сезон": {
    "1 серия": {
      "Kinogo": "cyx793so9kodfhdwiktl0r6b/264972"
    }
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question