react-native-redash
Version:
Utility library for React Native Reanimated
22 lines (21 loc) • 426 B
text/typescript
/**
* @worklet
*/
export const move = <T>(input: T[], from: number, to: number) => {
"worklet";
const offsets = input.slice();
while (from < 0) {
from += offsets.length;
}
while (to < 0) {
to += offsets.length;
}
if (to >= offsets.length) {
let k = to - offsets.length;
while (k-- + 1) {
offsets.push();
}
}
offsets.splice(to, 0, offsets.splice(from, 1)[0]);
return offsets;
};