Passed
Pull Request — master (#220)
by
unknown
02:04
created

server/src/Infrastructure/Common/Utils/ArrayUtils.ts   A

Complexity

Total Complexity 10
Complexity/F 1.67

Size

Lines of Code 23
Function Count 6

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 10
eloc 15
mnd 4
bc 4
fnc 6
dl 0
loc 23
rs 10
bpm 0.6666
cpm 1.6666
noi 0
c 0
b 0
f 0

2 Functions

Rating   Name   Duplication   Size   Complexity  
A ArrayUtils.range 0 10 3
A ArrayUtils.flatMap 0 7 2
1
export class ArrayUtils {
2
  public static range(start: number, end: number, step: number = 1) {
3
    function* generateRange() {
4
      let x = start - step;
5
      while (x <= end - step) {
6
        yield (x += step);
7
      }
8
    }
9
10
    return {
11
      [Symbol.iterator]: generateRange
12
    };
13
  }
14
15
  public static flatMap<T, V>(items: T[], fn: (x: T) => V[]): V[] {
16
    const arr = [];
17
    for (let item of items) {
18
      arr.push(...fn(item));
19
    }
20
    return arr;
21
  }
22
}
23