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

157
Views
¿Cuándo `return !stack.length` alguna vez devolverá `true`?

Estoy confundido por qué esta función alguna vez devolvería true . Si se agrega un elemento a la stack , devolver !stack.length devolvería false , ¿verdad? Creo que me falta algo sobre cómo funciona la pila, pero parece que no puedo encontrar la respuesta.

 var isValid = function (s) { const hash = { '(': ')', '{': '}', '[': ']', }; const stack = []; for (const char of s) { if (char in hash) stack.push(char); else { const top = stack.pop(); if (top === undefined || hash[top] !== char) { return false; } } } return !stack.length; };
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Eso sucederá cuando la longitud de la pila sea igual a 0. Poner un ! delante de stack.length evaluará NOT 0 . El resultado de esto es true .

Echa un vistazo aquí . O para ser muy específicos:

Si el valor se omite o es 0, -0, nulo, falso, NaN, indefinido o la cadena vacía (""), el objeto tiene un valor inicial de falso

about 4 years ago · Juan Pablo Isaza Report
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!