Tell us what’s happening:
I went a different route than the solutions provided. I used slice to make a shallow copy of the original array, from the start to (not including) index given.
Afterwards used splice normally, mutating the array, starting from index + 1 to get remaining elements. Avoiding the rule of splice-when start is greater than array length function is just adding.
Is this another proper solution? I hope my explanation makes sense.
Window.prototype.tabClose = function (index) {
var tabsBeforeIndex = this.tabs.slice(0, index); // used slice here
var tabsAfterIndex = this.tabs.splice(index + 1); // used splice here
this.tabs = tabsBeforeIndex.concat(tabsAfterIndex); // Join them together
return this;
};
Challenge: Understand the Hazards of Using Imperative Code
Link to the challenge: