Passed
Push — main ( d53ef8...c82fb0 )
by Andrii
01:47
created

research/syntax/template/docker/get.js   A

Complexity

Total Complexity 4
Complexity/F 4

Size

Lines of Code 25
Function Count 1

Duplication

Duplicated Lines 25
Ratio 100 %

Importance

Changes 0
Metric Value
wmc 4
eloc 16
mnd 3
bc 3
fnc 1
dl 25
loc 25
rs 10
bpm 3
cpm 4
noi 2
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
// NB COPYPASTE!
2
console.log(JSON.stringify(main(), null, 2))
3
4
function main() {
5
  const {env} = process
6
  , collected = {}
7
  , keys = []
8
9
  for (const key in env) {
10
    if (!key.includes("SPEC_"))
11
      continue
12
13
    collected[key] = env[key]
14
    keys.push(key)
15
  }
16
17
  const {length} = keys.sort()
18
  , $return = {}
19
20
  for (let i = 0; i < length; i++) {
21
    const key = keys[i]
22
    $return[key] = collected[key]
23
  }
24
25
  return $return
26
}
27