I need help understanding why these are different…
**Your code so far**
isEmpty() {
return this.collection.length === 0;
}
clear() {
return (this.collection.length = 0);
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36
.
Challenge: Create a Stack Class
Link to the challenge:
VasV
2
return this.collection.length === 0
Here you compare collection.length to zero. It can be rewritten as
if (this.collection.length === 0) {
return true;
} else return false;
return (this.collection.length = 0)
And here you’re setting collection.length to zero which leads to clearing the collection
system
Closed
3
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.