-
Notifications
You must be signed in to change notification settings - Fork 0
/
enchantments.js
102 lines (94 loc) · 2.09 KB
/
enchantments.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// @ts-check
/**
* Retrieve card from cards array at the 0-based position
*
* @param {number[]} cards
* @param {number} position
*
* @returns {number} the card
*/
export function getItem(cards, position) {
return cards[position];
}
/**
* Exchange card with replacementCard at the 0-based position
*
* @param {number[]} cards
* @param {number} position
* @param {number} replacementCard
*
* @returns {number[]} the cards with the change applied
*/
export function setItem(cards, position, replacementCard) {
cards[position] = replacementCard;
return cards;
}
/**
* Insert newCard at the end of the cards array
*
* @param {number[]} cards
* @param {number} newCard
*
* @returns {number[]} the cards with the newCard applied
*/
export function insertItemAtTop(cards, newCard) {
cards.push(newCard);
return cards;
}
/**
* Remove the card at the 0-based position
*
* @param {number[]} cards
* @param {number} position
*
* @returns {number[]} the cards without the removed card
*/
export function removeItem(cards, position) {
cards.splice(position, 1);
return cards;
}
/**
* Remove card from the end of the cards array
*
* @param {number[]} cards
*
* @returns {number[]} the cards without the removed card
*/
export function removeItemFromTop(cards) {
cards.pop();
return cards;
}
/**
* Insert newCard at beginning of the cards array
*
* @param {number[]} cards
* @param {number} newCard
*
* @returns {number[]} the cards including the new card
*/
export function insertItemAtBottom(cards, newCard) {
cards.unshift(newCard);
return cards;
}
/**
* Remove card from the beginning of the cards
*
* @param {number[]} cards
*
* @returns {number[]} the cards without the removed card
*/
export function removeItemAtBottom(cards) {
cards.shift();
return cards;
}
/**
* Compare the number of cards with the given stackSize
*
* @param {number[]} cards
* @param {number} stackSize
*
* @returns {boolean} true if there are exactly stackSize number of cards, false otherwise
*/
export function checkSizeOfStack(cards, stackSize) {
return cards.length === stackSize;
}