| Total Complexity | 3 |
| Complexity/F | 3 |
| Lines of Code | 22 |
| Function Count | 1 |
| Duplicated Lines | 22 |
| 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 PrefixToPostfix = (formula) => { |
||
| 9 | let result = "" |
||
|
|
|||
| 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 |