-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c7d3921
commit f91dda0
Showing
3 changed files
with
24 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import type { LengthProp } from '~/object/length-prop' | ||
|
||
/** | ||
* Swaps two elements in an array. | ||
* | ||
* @typeParam A - The input array. | ||
* @typeParam B - The index of the first element to swap. | ||
* @typeParam C - The index of the second element to swap. | ||
* @typeParam D - The resulting array after swapping the elements. | ||
*/ | ||
type Swap< | ||
A extends any[], | ||
B extends number, | ||
C extends number, | ||
D extends any[] = [], | ||
> = | ||
LengthProp<D> extends LengthProp<A> | ||
? D | ||
: LengthProp<D> extends B | ||
? Swap<A, B, C, [...D, A[C]]> | ||
: LengthProp<D> extends C | ||
? Swap<A, B, C, [...D, A[B]]> | ||
: Swap<A, B, C, [...D, A[LengthProp<D>]]> |