I am learning to write reducers for arrays. For example, one of the reducers changes array elements from integers to arrays.
Original state:
[0, 3, 5, 3, 9, 8]
Action:
case ADD_NEST:
return state.map(i => [i, action.payload]);
New state:
[[0, 0], [3, 0], [5, 0], [3, 0], [9, 0], [8, 0]]
I'm trying to write a reducer that would change the second element of sub-arrays based on the condition of the first one. (eg, if the first element of the subarray is greater than 3, change the second element to 1).
[[0, 0], [3, 0], [5, 1], [3, 0], [9, 1], [8, 1]]
so far I have (not much as I'm stuck):
case SET_BIT:
return state.map(i => (i[0] > 3 ? ??? : i));
Thank you for advice!