src/components/ebay-carousel/index.js
function getNextIndex(state, delta) {
    const { index, items, slideWidth, itemsPerSlide } = state;
    let i = index;
    let item;

    // If going backward from 0, we go to the end.
    if (delta === LEFT && i === 0) {
        i = items.length - 1;
    } else {
        // Find the index of the next item that is not fully in view.
        do {
            item = items[i += delta];
        } while (item && item.fullyVisible);

        if (delta === LEFT && !itemsPerSlide) {
            // If going left without items per slide, go as far left as possible while keeping this item fully in view.
            const targetOffset = item.right - slideWidth;
            do {
                item = items[--i];
            } while (item && item.left >= targetOffset);
            i += 1;
        }
    }

    return normalizeIndex(state, i);
}
function getNextIndex(state, delta) {
    const { index, items, slideWidth, itemsPerSlide } = state;
    let i = index;
    let item;

    // If going backward from 0, we go to the end.
    if (delta === LEFT && i === 0) {
        i = items.length - 1;
    } else {
        // Find the index of the next item that is not fully in view.
        do {
            item = items[i += delta];
        } while (item && item.fullyVisible);

        if (delta === LEFT && !itemsPerSlide) {
            // If going left without items per slide, go as far left as possible while keeping this item fully in view.
            const targetOffset = item.right - slideWidth;
            do {
                item = items[--i];
            } while (item && item.left >= targetOffset);
            i += 1;
        }
    }

    return normalizeIndex(state, i);
}
function getNextIndex ( state , delta ) { const { index , items , slideWidth , itemsPerSlide } = state ; let i = index ; let item ; // If going backward from 0, we go to the end. if ( delta === LEFT && i === 0 ) { i = items . length - 1 ; } else { // Find the index of the next item that is not fully in view. do { item = items [ i += delta ] ; } while ( item && item . fullyVisible ) ; if ( delta === LEFT && ! itemsPerSlide ) { // If going left without items per slide, go as far left as possible while keeping this item fully in view. const targetOffset = item . right - slideWidth ; do { item = items [ -- i ] ; } while ( item && item . left >= targetOffset ) ; i += 1 ; } } return normalizeIndex ( state , i ) ; }
Calculates the next valid index in a direction.

@param {object} state The widget state.
@param {-1|1} delta 1 for right and -1 for left.
@return {number}
Calculates the next valid index in a direction .