Move Cards on a Kanban Board
Write the code, see it run, pass the checks.
The problem
- hard
- Code
- Pro
Write the reducer behind a kanban board and export it by name: boardReducer(board, action) returns the next board. A board is an object with three columns, { todo, doing, done }, each an array of card titles (strings) from top to bottom, and a title appears at most once on the whole board. { type: "add", title } trims the title and puts it at the end of todo, but is ignored if the trimmed title is empty or already on the board. { type: "move", title, to, index } takes the card out of its column and puts it in the column named by to ("todo", "doing" or "done") at position index, counted after the card has been taken out, so moving within one column reorders it. Without an index the card goes at the end; an index below 0 means the top, and one past the end means the end. { type: "remove", title } takes the card off the board. An action naming a card or column that doesn't exist, or with an unknown type, is ignored: return the same board object. Never modify the board you're given. The default export App is a small board for the preview; the checks test boardReducer itself.
Your code must pass
- add puts a new card at the end of todo
- add ignores blank and duplicate titles
- move takes a card to the end of another column
- move with an index puts the card at that position
- remove takes a card off the board
- Ignores unknown cards, columns and actions
- Never changes the board it's given