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

234
Visualizações
How to determine if value exists in target node or descendant nodes via a Tree?

Here is the input code:

  var newTree = {};
  newTree.value = value;
  newTree.children = [] // fix me
  
  Object.assign(newTree, treeMethods)
  
  return newTree;
};

var treeMethods = {};

treeMethods.addChild = function(value) {
    const newNode = Tree(value);
    this.children.push(newNode)
};

treeMethods.contains = function(target) {
    let currentTree = this.children
    while (currentTree != null) {
        if (currentTree.indexOf(target) > -1) return true
        currentTree = this.children[target]
    }
    return false
    
}; 

I am trying to determine if, given a target value via the contains function, can I find the target value called to contains() in parent nodes or descendant nodes.

Please don't give me the full answer but if you could push me in the right direction.

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