Total Complexity | 4 |
Complexity/F | 2 |
Lines of Code | 22 |
Function Count | 2 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | export default linearizeEncodings; |
||
2 | |||
3 | // Encodings can be nestled like [[1-1, 1-2], 2, [3-1, 3-2] |
||
4 | // Convert to [1-1, 1-2, 2, 3-1, 3-2] |
||
5 | function linearizeEncodings(encodings){ |
||
6 | var linearEncodings = []; |
||
7 | function nextLevel(encoded){ |
||
8 | if(Array.isArray(encoded)){ |
||
9 | for(let i = 0; i < encoded.length; i++){ |
||
10 | nextLevel(encoded[i]); |
||
11 | } |
||
12 | } |
||
13 | else{ |
||
14 | encoded.text = encoded.text || ""; |
||
15 | encoded.data = encoded.data || ""; |
||
16 | linearEncodings.push(encoded); |
||
17 | } |
||
18 | } |
||
19 | nextLevel(encodings); |
||
20 | |||
21 | return linearEncodings; |
||
22 | } |
||
23 |