param { number } moveAmount param { number } initialIndex param { number } itemCount returns { number } const getNextWrappingIndex = ( moveAmount , initialIndex , itemCount ) => { const itemsLastIndex = itemCount - 1 ; if ( typeof initialIndex !== 'number' || initialIndex < 0 || initialIndex >= itemCount ) { initialIndex = moveAmount > 0 ? - 1 : itemsLastIndex + 1 ; } const newIndex = initialIndex + moveAmount ; if ( newIndex < 0 ) { return itemsLastIndex ; } if ( newIndex > itemsLastIndex ) { return 0 ; } return newIndex ; } ; export default getNextWrappingIndex ;