Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

164
Visualizações
Javascript trees very simple question from a newbie

I have searched the internet very carefully but it seems impossible to get som simple answers regarding trees that is not binary trees and that will not interact with the DOM. I start with some code that i found so that it will be easier to understand what i really would like to understand.

funcion Node (data){
    this.data = data;
    this.parent = null;
    this.children = [];}

function Tree (data){
    var node = new Node (data);
    this._root = node;}

var tree = new Tree ('one');

tree._root.children.push (new Node('two'));
tree._root.children[0].parent = tree;

tree._root.children.push (new Node('three'));
tree._root.children[0].parent = tree;

tree._root.children.push (new Node('four'));
tree._root.children[0].parent = tree;

So - This code will create a Tree with the topnode = 'one' and three children called 'two', 'three' and 'four'.

  1. If i now - directly in the code on the line following the last line in the code above want to delete the tree childrens, what would that code look like ? I simply cant fint the keyword for doing that. Is is "deleteChild" or "delete Node" or remove Node - or something else ?

  2. As i understand from the code this tree is using a single string to store user data - in this case 'one' and 'two' and so on. If i would instead like to use a string array with three values for example 'Chris', 72, 'Orange' - how would that code look like in the above eample ?

  3. Where can I myself find fact regarding all the keywords and commands that you use when you are working with n-ary trees ? Would be very very grateful for links !

Kind Regards

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda