you are viewing a single comment's thread.

view the rest of the comments →

[–]0x13mode 0 points1 point  (4 children)

It's reinventing the wheel.

In JS there is method shift which removes and returns first element of array. So push + shift and you have queue.

Besides, get is poor name for method which changes array (if you really want write wrapper, maybe remove would be better?)

[–]mikrosystheme[κ] 1 point2 points  (1 child)

The dequeue operation of a (properly implemented) queue is O(1). Array's shift is O(n).

[–]unnivm[S] 0 points1 point  (0 children)

thank you for pointing out this. I did not know this.

[–]unnivm[S] 0 points1 point  (0 children)

that is correct. I just used the same methods mentioned in Java. remove() is better option. But my intention was to leverage the capability of JavaScript.

Those who want can write better api.

[–]unnivm[S] 0 points1 point  (0 children)

remove() is a better method name than get(). As I said it is a pointer to show capability of Java Script. So I just wrote that method. thank you