As a magician-to-be, Elyse needs to practice some basics. She has a stack of cards that she wants to manipulate.
To make things a bit easier she only uses the cards 1 to 10.
Return the card at position index
from the given stack.
const index = 2
getItem([1, 2, 4, 1], index)
// => 4
Exchange the card at position index
with the new card provided and return the adjusted stack.
Note that this will also change the input slice which is ok.
const index = 2
const newCard = 6
setItem([1, 2, 4, 1], index, newCard)
// => [1, 2, 6, 1]
Insert new card at the top of the stack and return the stack.
const newCard = 8
insertItemAtTop([5, 9, 7, 1], newCard)
// => [5, 9, 7, 1, 8]
Remove the card at position index
from the stack and return the stack.
const index = 2
removeItem([3, 2, 6, 4, 8], index)
// => [3, 2, 4, 8]
Remove the card at the top of the stack and return the stack.
removeItemFromTop([3, 2, 6, 4, 8])
// => [3, 2, 6, 4]
Insert new card at the bottom of the stack and return the stack.
const newCard = 8
insertItemAtBottom([5, 9, 7, 1], newCard)
// => [8, 5, 9, 7, 1]
Remove the card at the bottom of the stack and return the stack.
removeItemAtBottom([8, 5, 9, 7, 1])
// => [5, 9, 7, 1]
Check whether the size of the stack is equal a given stackSize
or not.
const stackSize = 4
checkSizeOfStack([3, 2, 6, 4, 8], stackSize)
// => false