this challenge is a little bit OOP and there are parts that I don’t understand I am trying to understand it line by line
this part here is not clear to me in this method tabClose we have two constants tabsBeforeIndex and tabsAfterIndex I would like to understand what tabs beforeIndex really mean are it going to splice the array from 0 as the first parameter and the second parameter index will delete this amount of items in the array. and what about the second constants what it equal if the first constants started to splice from 0 ?
// 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(1); // Get the tabs after the tab
this.tabs = tabsBeforeIndex.concat(tabsAfterIndex); // Join them together
// Only change code above this line
Yes, that is what the splice method does, it removes items from an array and returns the items it removed. The first arg is the index in the array to start deleting and the second arg is how many items to delete starting at that index. tabsBeforeIndex will then be an array of the deleted items.
I’m not sure I understand this question. The first splice does start at 0. After the first splice then the first element in this.tabs will be the tab at index because the first splice deleted all of the elements before index but not index itself. The second splice starts at 1 which will delete everything after the first element in this.tabs.
ok so the first constant contains the tabs from the first element to the element has the index equals to index parameter
but what about the second parameter I do not know what it really equals you said it equals the elements from index 1 to the end but I cannot grasp it
if tabsAfterIndex equals tabs.splice(1) so all the next elements will be from index 1 to the end of the array but we already spliced the tabs from 0 to the specified index
how after that tabs equals tabsBeforeIndex and tabsAfterIndex this is complicating
I hate to be “that guy”, but like I said, if in doubt, go to the docs. After reading the first sentence in the doc, you tell me
I’m not trying to be a jerk here. This is good practice. You need to get comfortable reading documentation because professional developers spend a lot of time doing this.
Look at my example above. What is the first item in the array after the first splice?