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

125
Views
aprendiendo sobre matrices, tratando de implementar la conversión de postfijos a resultados

Tengo el siguiente sufijo para convertir:

 outputArray = [3,4,*,2,9,3,/,4,/,6]

El resultado buscado es slicedArray = [3, * , 4 ] para que pueda realizar operaciones aritméticas.

Este fue mi enfoque que falló por alguna razón...

 let outputArray = ['3','4','*','2','9','3','/','4','/','6'] outputArray.forEach((element) => { while (( element !== '*' || element !== '+' || element !== '-' || element !== '/' || element !== '^' )) { resultArray.push(outputArray.shift(element)); console.log("Hi Panda " + resultArray) } if (element.includes("+") || element.includes("-") || element.includes("*") || element.includes("/") || element.includes("^")) { let panda = resultArray.length; resultArray.splice(panda - 1, 0, element) let slicedArray = resultArray.slice(-3) console.log(slicedArray); } })

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Puede usar una pila y empujar todo el valor hasta que obtenga un operador, luego agregue una nueva matriz con el valor izquierdo y reich y el operador.

 const operators = ['+', '-', '*', '/'], data = [3, 4, '*', 2, 9, 3, '/', 4, '/', 6], stack = []; for (const value of data) { if (operators.includes(value)) { const b = stack.pop(), a = stack.pop(); stack.push([a, value, b]); continue; } stack.push(value); } console.log(stack);
 .as-console-wrapper { max-height: 100% !important; top: 0; }

Un enfoque para obtener el valor.

 const operators = { '+': (a, b) => a + b, '-': (a, b) => a - b, '*': (a, b) => a * b, '/': (a, b) => a / b }, data = [3, 4, '*', 2, 9, 3, '/', 4, '/', 6], stack = []; for (const value of data) { if (value in operators) { const b = stack.pop(), a = stack.pop(); stack.push(operators[value](a, b)); continue; } stack.push(value); } console.log(stack);
 .as-console-wrapper { max-height: 100% !important; top: 0; }

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!