Reorder an array in place to match a list of new indexes
Given an array of items and a corresponding array of new index positions, write a function to reorder the items array according to the new index positions provided. Your function should mutate the original items array to reflect the new order. To reorder an array by new indexes in place, avoid helpers such as Array.prototype.map() that return a new array.
This challenge tests your understanding of array manipulation and sorting algorithms. It’s a common task in frontend development, especially when dealing with dynamic user interfaces where elements might need reordering based on user actions or other criteria.
Example:
Input: items = ["a", "b", "c", "d", "e"], newOrder = [3, 0, 4, 1, 2]
Output: items becomes ["b", "d", "e", "a", "c"]
The function should take two arguments:
items: An array of elements that need to be reordered.newOrder: An array of integers representing the new index positions for each corresponding element in the items array.The goal is to mutate the items array such that each element is moved to its new index as specified by the newOrder array. Ensure your solution accounts for the possibility of various data types within the items array and handles edge cases gracefully.