Efficient algorithm for removing items from an array in place
问题 I'm looking for an efficient JavaScript utility method that in O(n) will remove a set of items from an array in place . You can assume equality with the === operator will work correctly. Here is an example signature (written in TypeScript for type clarity) function deleteItemsFromArray<T>(array: T[], itemsToDelete: T[]) { ... } My thought is to do this in two passes. The first pass gets the indexes that need to be removed. The second pass then compacts the array by copying backwards from the