Total Complexity | 17 |
Complexity/F | 3.4 |
Lines of Code | 43 |
Function Count | 5 |
Duplicated Lines | 1 |
Ratio | 2.33 % |
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 | 'use strict'; |
||
2 | |||
3 | if (!process.version || |
||
4 | process.version.indexOf('v0.') === 0 || |
||
5 | process.version.indexOf('v1.') === 0 && process.version.indexOf('v1.8.') !== 0) { |
||
6 | module.exports = { nextTick: nextTick }; |
||
7 | } else { |
||
8 | module.exports = process |
||
9 | } |
||
10 | |||
11 | View Code Duplication | function nextTick(fn, arg1, arg2, arg3) { |
|
|
|||
12 | if (typeof fn !== 'function') { |
||
13 | throw new TypeError('"callback" argument must be a function'); |
||
14 | } |
||
15 | var len = arguments.length; |
||
16 | var args, i; |
||
17 | switch (len) { |
||
18 | case 0: |
||
19 | case 1: |
||
20 | return process.nextTick(fn); |
||
21 | case 2: |
||
22 | return process.nextTick(function afterTickOne() { |
||
23 | fn.call(null, arg1); |
||
24 | }); |
||
25 | case 3: |
||
26 | return process.nextTick(function afterTickTwo() { |
||
27 | fn.call(null, arg1, arg2); |
||
28 | }); |
||
29 | case 4: |
||
30 | return process.nextTick(function afterTickThree() { |
||
31 | fn.call(null, arg1, arg2, arg3); |
||
32 | }); |
||
33 | default: |
||
34 | args = new Array(len - 1); |
||
35 | i = 0; |
||
36 | while (i < args.length) { |
||
37 | args[i++] = arguments[i]; |
||
38 | } |
||
39 | return process.nextTick(function afterTick() { |
||
40 | fn.apply(null, args); |
||
41 | }); |
||
42 | } |
||
43 | } |
||
44 | |||
45 |