Přidat otázku mezi oblíbenéZasílat nové odpovědi e-mailem Jaky napsat script v JS který vygeneruje takový objekt

function parse(input) {
  const result = [];
  const stack = [];
  const lines = input.split("\n");
  let indent = 0;
  let col = result;
  let item;
  for (let i = 0; i < lines.length; i++) {
    const line = lines[i];
    let curInd = 0;
    while (line[curInd] === " ") curInd++;
    if (curInd > indent) {
      stack.push({ indent, col });
      col = item.children;
    }
    if (curInd < indent) {
      let s;
      do {
        s = stack.pop();
      } while (s.indent > curInd)
      col = s.col;
    }
    indent = curInd;
    item = {
        description: line.substr(curInd),
        children: []
    };
    col.push(item);
  }
  console.log(JSON.stringify(result, null, 2));
}

Reakce na odpověď

1 Zadajte svou přezdívku:
2 Napište svou odpověď:
3 Pokud chcete dostat ban, zadejte libovolný text:

Zpět do poradny