invertase / denque

The fastest javascript implementation of a double-ended queue. Used by the official Redis, MongoDB, MariaDB & MySQL libraries for Node.js and many other libraries.
https://docs.page/invertase/denque
Apache License 2.0
354 stars 33 forks source link

push(undefined) has a confusing behavior #25

Closed rinick closed 3 years ago

rinick commented 4 years ago

https://github.com/invertase/denque/blob/ebe332be31c04754e820c0118fdc5bdb8dd2d4e0/index.js#L131

in js Array you can push(undefined) or unshift(undefined) and it works exactly as what people expect. in Denque, push(undefined) is ignored and wont change the queue at all.

So if someone just replaces his Array with Denque for better performance, he might hit this hidden trap and spend hours to figure out what causes the new issues.

rinick commented 4 years ago

and the readme also says

If the queue is empty, undefined is returned. 
If you need to differentiate between undefined values in the queue and pop() return value,
check the queue .length before popping.

Which implies undefined value is allowed in the Denque. But that's not the case

Salakar commented 3 years ago

Fixed this in #35 - releasing v2.0.0 shortly - sorry it took a while 😅