Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

162
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!