Skip to content
This repository has been archived by the owner on Sep 2, 2022. It is now read-only.

Commit

Permalink
Implement array reorder util
Browse files Browse the repository at this point in the history
  • Loading branch information
Ray Foo committed Aug 26, 2022
1 parent 0e64b84 commit 04a06f6
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/stupid-nails-ring.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@busyxiang/utilities-js': patch
---

Add array reorder util
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Changesets
on:
push:
branches:
- main
- release

env:
CI: true
Expand Down
11 changes: 11 additions & 0 deletions src/array.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export const reorder = <T>(
arr: T[],
startIndex: number,
endIndex: number,
): T[] => {
const result = Array.from(arr);
const [removed] = result.splice(startIndex, 1);
result.splice(endIndex, 0, removed);

return result;
};
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { reorder } from './array';
export { alphabeticalSort, countSort } from './sorter';

0 comments on commit 04a06f6

Please sign in to comment.