I encountered an issue while solving an algorithmic problem yesterday, which goes thus.
remove() {
// your code here
if(!this.arr.length) {
return -1;
}
else if(this.arr.length) {
return this.arr[0];
this.arr.splice(0, 1);
}
}
Note:- This is part of one of the class methods.
I wanted to get the item in the zero index before splicing that same item out. Then I realized that a code after a return statement is called an unreachable code and therefore, won't be executed.