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

153
Visualizações
JS Object Mapping Quesions

I've been trying to understanding this part of the code:

if(stack.length > 0 && map[stack[stack.length - 1]] === s[i])

at line 9. What does the "map[stack[stack.length-1]]" mean? At first I thought the map is an object, but I think you are supposed to add " " mark around the properties. Is map a data structure? if it is, How can I use this data structure?

    var stack = [];
    var len =  s.length;
    var map = {
        '(': ')',
        '[': ']',
        '{': '}',
    };
    for(var i = 0; i<len; i++){
        if(stack.length > 0 && map[stack[stack.length - 1]] === s[i]) {
            stack.pop();
        }else{
            stack.push(s[i]);
        }

    }
    return stack.length === 0;
};
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Map is an object and

map[stack[stack.length - 1]]

is the property of 'map' wich key is the value of the last element of the array stack. As properties of an object can be accessed both these ways

const object = {
"property1" : value1,
"property2" : value2,
}
object.property1 == object['property1']; // is true
object.property2 == object['property2']; // is also true
about 4 years ago · Juan Pablo Isaza Relatório
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