Narrative Theme - Remove Blank page at the end of slideshow

Hello,

I have added the following code to my “Custom.js” file so that the narrative theme slideshow can be autoplay

var sections = window.theme.sections;
var slideshowAutoExtension = {
  init: function() {
    this.on('slideshow_desktop_init_done', this._autoplaySlideshow.bind(this));
  },
  _autoplaySlideshow: setInterval(function() {
    var $slide = $('.slideshow__slide--active')
                   .removeClass('slideshow__slide--active');

    var $button = $('.slideshow__button--active')
                   .removeClass('slideshow__button--active');

    var $slides = $('.slideshow__slide');

    var currentIndex = ($slides.index($slide) + 1) % $slides.length;

    $slides
      .eq(currentIndex)
      .addClass('slideshow__slide--active');

    var $buttons = $('.slideshow__button')
      .eq(currentIndex)
      .addClass('slideshow__button--active');

  }, 3000)

};

sections.extend('slideshow', slideshowAutoExtension);

But now my issue is at the end of my slideshow there is a blank slide. Can someone please advise on how I can alter the code files to remove the blankslide?