Passed
Push — master ( 8a294e...6fd7ff )
by Nguyen
33s queued 10s
created

topics/stack/postfix-to-prefix/index.js   A

Complexity

Total Complexity 3
Complexity/F 3

Size

Lines of Code 24
Function Count 1

Duplication

Duplicated Lines 24
Ratio 100 %

Importance

Changes 0
Metric Value
wmc 3
eloc 19
mnd 2
bc 2
fnc 1
dl 24
loc 24
rs 10
bpm 2
cpm 3
noi 0
c 0
b 0
f 0

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1 View Code Duplication
const Stack = require('../index.js');
2
const operators = {
3
    "+": true,
4
    "-": true,
5
    "*": true,
6
    "/": true,
7
}
8
const PostfixToPrefix = (formula) => {
9
    let stack = new Stack()
10
    for (let i = 0; i < formula.length; i++) {
11
        let c = formula[i]
12
        if (!operators[c]) {
13
            stack.push(c)
14
            continue
15
        }
16
        let subFormula = stack.pop()
17
        subFormula = stack.pop() + subFormula
18
        subFormula = c + subFormula
19
        stack.push(subFormula)
20
21
    }
22
    return stack.pop()
23
}
24
module.exports = PostfixToPrefix
25
26