Skip to content

Commit

Permalink
fix : EsLint error
Browse files Browse the repository at this point in the history
  • Loading branch information
dasom-jo committed Jan 2, 2025
1 parent 2f2fd53 commit c89c102
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/array/reduce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,22 @@
export function reduce<T>(arr: T[], indicesToRemove: number[]): Array<T | undefined> {
// Normalize indices and sort in descending order
const indicesSet = Array.from(
new Set(indicesToRemove.map(index => (index < 0 ? arr.length + index : index)))
new Set(
indicesToRemove.map((index) => (index < 0 ? arr.length + index : index))
)
).sort((a, b) => b - a);

const removed: Array<T | undefined> = [];

// Remove elements at specified indices
indicesSet.forEach(index => {
for (const index of indicesSet) {
if (index >= 0 && index < arr.length) {
removed.unshift(arr[index]); // Add the removed element to the front
arr.splice(index, 1); // Remove the element from the array
} else {
removed.unshift(undefined); // Handle out-of-bounds indices
}
});
}

return removed;
}

0 comments on commit c89c102

Please sign in to comment.