Using array index as key breaks when prepending. Items carry editable state. Input: line 1 — JSON array of item names with state {"name":..., "draft":...}; line 2 — a new item name prepended with empty draft. With index keys, state sticks to positions! Print the resulting (name, draft) pairs as JSON after prepending with index keys.
Input: two lines.
Output: JSON array of {name, draft} showing the misalignment.
Your program reads from stdin and prints to stdout.
Example 1
Input: [{"name":"a","draft":"typing-a"},{"name":"b","draft":"typing-b"}] new
Output: [{"name":"new","draft":"typing-a"},{"name":"a","draft":"typing-b"},{"name":"b","draft":""}]
Hints
Using array index as key breaks when prepending. Items carry editable state. Input: line 1 — JSON array of item names with state {"name":..., "draft":...}; line 2 — a new item name prepended with empty draft. With index keys, state sticks to positions! Print the resulting (name, draft) pairs as JSON after prepending with index keys.
Input: two lines.
Output: JSON array of {name, draft} showing the misalignment.
Your program reads from stdin and prints to stdout.
Example 1
Input: [{"name":"a","draft":"typing-a"},{"name":"b","draft":"typing-b"}] new
Output: [{"name":"new","draft":"typing-a"},{"name":"a","draft":"typing-b"},{"name":"b","draft":""}]
Hints