src/cardDeck/cardDeck.js   A
last analyzed

Size

Lines of Code 69

Duplication

Duplicated Lines 0
Ratio 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
nc 1
dl 0
loc 69
rs 10
ccs 12
cts 12
cp 1
noi 2

1 Function

Rating   Name   Duplication   Size   Complexity  
A cardDeck.js ➔ ??? 0 8 2
1
/**
2
 * A module for a deck of cards.
3
 *
4
 * @module
5
 */
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]];
0 ignored issues
show
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 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...
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