Problem, as an interviewer would state it: "Implement the CORE reordering logic for a drag-and-drop sortable list — given the array, the dragged item index, and the drop target index — WITHOUT using any external library."
Examples:
reorder(["a","b","c","d","e"], 0, 3); // ["b","c","d","a","e"] -- "a" moved to position 3
Clarifying questions expected:
- Should this function mutate the input array in place, or return a brand-new array?
- Should this be a general PURE reordering function, separate from the real POINTER-EVENT wiring that determines the from/to indices during an actual drag gesture?
- What happens if fromIndex equals toIndex — should it genuinely be a safe no-op?
Code / implementation expected: Yes — real, direct proof of the pure reorder logic across multiple real moves, including a same-index no-op and confirming the original array is genuinely untouched.