Passed
Push — master ( 09a54a...cba1d2 )
by Muhammad Dyas
01:26
created

utils.js ➔ getRandomWinners   A

Complexity

Conditions 2

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 2
1
2
/**
3
 * @param {array} names - list of names
4
 * @param {integer} winnerCount - total winner that picked from names
5
 * @returns {array} - list of winner
6
 */
7
export function getRandomWinners(names, winnerCount = 1) {
8
  for (let i = names.length - 1; i > 0; i--) {
9
    const j = Math.floor(Math.random() * (i + 1));
10
    [names[i], names[j]] = [names[j], names[i]];
0 ignored issues
show
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...
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...
11
  }
12
  return names.slice(0, winnerCount);
13
}
14