equal-vue
Version:
Equal is a Vue 3 hackable UI library empowered by tailwindcss
20 lines (17 loc) • 442 B
text/typescript
import { EDirections } from '@/models/enums'
type Props = {
direction: EDirections
array: []
curIndex: number
}
export const getArrayIndexByDirection = ({
direction,
array,
curIndex,
}: Props): number => {
const resultMap = {
[EDirections.UP]: curIndex <= 0 ? array.length - 1 : curIndex - 1,
[EDirections.DOWN]: curIndex === array.length - 1 ? 0 : curIndex + 1,
}
return resultMap[direction]
}