Issues (33)

topics/stack/prefix-to-postfix/index.js (1 issue)

Severity
1 View Code Duplication
const Stack = require('../index.js');
2
const operators = {
3
    "+": true,
4
    "-": true,
5
    "*": true,
6
    "/": true,
7
}
8
const PrefixToPostfix = (formula) => {
9
    let result = ""
0 ignored issues
show
The variable result seems to be never used. Consider removing it.
Loading history...
10
    let stack = new Stack()
11
    for (let i = formula.length - 1 ; i>= 0; i--) {
12
        let c = formula[i]
13
        if (!operators[c]) {
14
            stack.push(c)
15
            continue
16
        }
17
	    let subFormula = stack.pop() + stack.pop() + c
18
		     stack.push(subFormula)
19
    }
20
    return stack.pop()
21
}
22
module.exports = PrefixToPostfix
23
24