Completed
Push — master ( 4e1210...2759f8 )
by Muhammad Dyas
16s queued 13s
created

src/helpers/utils.js   A

Complexity

Total Complexity 4
Complexity/F 1.33

Size

Lines of Code 16
Function Count 3

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 8
mnd 1
bc 1
fnc 3
dl 0
loc 16
rs 10
bpm 0.3333
cpm 1.3333
noi 4
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A utils.js ➔ extractMessage 0 4 2
1
/**
2
 * @param {array} names - list of names
3
 * @param {integer} winnerCount - total winner that picked from names
0 ignored issues
show
Documentation introduced by
The parameter winnerCount does not exist. Did you maybe forget to remove this comment?
Loading history...
4
 * @returns {array} - list of winner
5
 */
6
export function getRandomWinners(names, winnerCount = 1) {
7
  for (let i = names.length - 1; i > 0; i--) {
8
    const j = Math.floor(Math.random() * (i + 1));
9
    [names[i], names[j]] = [names[j], names[i]];
0 ignored issues
show
Bug introduced by
The variable names seems to be never declared. If this is a global, consider adding a /** global: names */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Bug introduced by
The variable j seems to be never declared. If this is a global, consider adding a /** global: j */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Bug introduced by
The variable i seems to be never declared. If this is a global, consider adding a /** global: i */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
10
  }
11
  return names.slice(0, winnerCount);
12
}
13
14
/**
15
 * @param {string} string - text that will be extracted
16
 * @returns {array} list of extracted text
17
 */
18
export function extractMessage(string) {
19
  const regex = /"[^"]+"|[^\s]+/g;
20
  return string.match(regex).map((s) => s.replace(/"(.+)"/, '$1'));
21
}
22