| Total Complexity | 3 |
| Complexity/F | 3 |
| Lines of Code | 24 |
| Function Count | 1 |
| Duplicated Lines | 24 |
| Ratio | 100 % |
| Changes | 0 | ||
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 |