Advertisement
Guest User

Untitled

a guest
Feb 25th, 2020
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. function polishNotation(operators) {
  2. const numbers = [];
  3. const actions = {
  4. '+':(a, b) => a + b,
  5. '-':(a, b) => a - b,
  6. '*':(a, b) => a * b,
  7. '/':(a, b) => a / b,
  8. };
  9. for (let i = 0; i < operators.length; i += 1) {
  10. if(Number(operators[i])) {
  11. numbers.push(Number(operators[i]));
  12. } else {
  13. const secondNum = numbers.pop();
  14. const firstNum = numbers.pop();
  15. numbers.push(actions[operators[i]](firstNum,secondNum))
  16. }
  17. }
  18. return numbers;
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement