What I try is to check the state.newCardArray and remove that item based on index and then push it to state.arrayFoldedCards. This is a card game, so if the newCardArray is empty and there is no winner or loser, then the game stops....
const initialState = {
newCardArray: ['a', 'b', 'c']; // after removing the array looks like ['a', 'c']
arrayFoldedCards: [] // pushing to the array resulted in an updated array that looks like ['b']
}
export const game = (state = initialState, action) => {
switch (action.type) {
case types.GET_CARD:
{
const getRandomNumber = Math.floor(state.newCardArray.length * Math.random());
console.log(state.newCardArray);
console.log(state.arrayFoldedCards);
return {
...state,
randomNumber: getRandomNumber,
arrayFoldedCards: state.newCardArray[getRandomNumber].push(state.arrayFoldedCards.pop())
}
}
}
}
newCardArray[getRandomNumber]will give you an element from the array callingnewCardArray[getRandomNumber].push()means you expect that element to be an array and you want to add an item to the sub-array. Since you have plain strings, that's not going to work.