Lines of Code | 69 |
Duplicated Lines | 0 |
Ratio | 0 % |
Coverage | 100% |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | /** |
||
6 | "use strict"; |
||
7 | |||
8 | //const Card = require("../card/card"); |
||
9 | |||
10 | class CardDeck { |
||
11 | /** |
||
12 | * @constructor |
||
13 | * |
||
14 | * @param {object} options - Configure by sending options. |
||
15 | */ |
||
16 | constructor(options = {}) { |
||
17 | 4 | this.numberOfDecks = options.numberOfDecks || 2; |
|
18 | 4 | this.numberOfCards = options.numberOfCards || 52; |
|
19 | 4 | this.decks = []; |
|
20 | 4 | for (let i = 0; i < this.numberOfDecks * 52; i++) { |
|
21 | 416 | this.decks.push(i % this.numberOfCards); |
|
22 | } |
||
23 | } |
||
24 | |||
25 | |||
26 | |||
27 | /** |
||
28 | * Get number of cards in deck. |
||
29 | * |
||
30 | * @returns {integer} The amount of cards in the deck. |
||
31 | */ |
||
32 | getNumberOfCards() { |
||
33 | 2 | return (this.decks.length); |
|
34 | } |
||
35 | |||
36 | |||
37 | |||
38 | /** |
||
39 | * Show all cards by their id. |
||
40 | * |
||
41 | * @returns {array} With all cards. |
||
42 | */ |
||
43 | showAllCardsById() { |
||
44 | 2 | return (this.decks.slice()); |
|
45 | } |
||
46 | |||
47 | |||
48 | |||
49 | /** |
||
50 | * Shuffle the deck. |
||
51 | * |
||
52 | * @returns {void} |
||
53 | */ |
||
54 | shuffle() { |
||
55 | 2 | for (let i = this.decks.length - 1; i > 0; i--) { |
|
56 | 206 | const j = Math.floor(Math.random() * (i + 1)); |
|
57 | |||
58 | 206 | [this.decks[i], this.decks[j]] = [this.decks[j], this.decks[i]]; |
|
59 | } |
||
60 | } |
||
61 | |||
62 | |||
63 | |||
64 | /** |
||
65 | * Get a card from the deck, remove it from the deck. |
||
66 | * |
||
67 | * @returns {integer} As card id. |
||
68 | */ |
||
69 | getCard() { |
||
70 | 105 | return (this.decks.pop()); |
|
71 | } |
||
72 | } |
||
73 | |||
74 | module.exports = CardDeck; |
||
75 |
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.