Understand the Hazards of Using Imperative Code

Hello. I do not understand this challenge. Especially lines 23-26, I cannot make sense of them. Can some explain it to me please?

which challenge is this? can you give the link to the challenge, and the code you need help with?

Functional Programming: Understand the Hazards of Using Imperative Code | freeCodeCamp.org

what code do you need help with?

I need help with lines 23-26

please post the code you need help with
what do you not understand of this code?

// tabs is an array of titles of each site open within the window
const Window = function(tabs) {
this.tabs = tabs; // We keep a record of the array inside the object
};

// When you join two windows into one window
Window.prototype.join = function(otherWindow) {
this.tabs = this.tabs.concat(otherWindow.tabs);
return this;
};

// When you open a new tab at the end
Window.prototype.tabOpen = function(tab) {
this.tabs.push(‘new tab’); // Let’s open a new tab for now
return this;
};

// When you close a tab
Window.prototype.tabClose = function(index) {

// Only change code below this line

const tabsBeforeIndex = this.tabs.splice(0, index); // Get the tabs before the tab
const tabsAfterIndex = this.tabs.splice(index + 1); // Get the tabs after the tab

this.tabs = tabsBeforeIndex.concat(tabsAfterIndex); // Join them together

// Only change code above this line

return this;
};

// Let’s create three browser windows
const workWindow = new Window([‘GMail’, ‘Inbox’, ‘Work mail’, ‘Docs’, ‘freeCodeCamp’]); // Your mailbox, drive, and other work sites
const socialWindow = new Window([‘FB’, ‘Gitter’, ‘Reddit’, ‘Twitter’, ‘Medium’]); // Social sites
const videoWindow = new Window([‘Netflix’, ‘YouTube’, ‘Vimeo’, ‘Vine’]); // Entertainment sites

// Now perform the tab opening, closing, and other operations
const finalTabs = socialWindow
.tabOpen() // Open a new tab for cat memes
.join(videoWindow.tabClose(2)) // Close third tab in video window, and join
.join(workWindow.tabClose(1).tabOpen());
console.log(finalTabs.tabs);

This is the part I need help with

// Only change code below this line

const tabsBeforeIndex = this.tabs.splice(0, index); // Get the tabs before the tab
const tabsAfterIndex = this.tabs.splice(index + 1); // Get the tabs after the tab

this.tabs = tabsBeforeIndex.concat(tabsAfterIndex); // Join them together

// Only change code above this line

please talk to me, what do you understand and what do you not understand of that line? I don’t know how to help you if you don’t tell me anything

I do not understand what these lines mean. Can you explain what splice is executing on both lines? and how I go about solving this problem?

splice is executing on this.tabs, which is an array and it rapresents the open tabs in a browser. Now, this is also the debugging section, so you need to remember how splice works. splice remove elements from an array and returns an array with the removed elements.