Skip to content

Bug in sequence? #59

Description

@raganwald

I just finished working through your extension of a queue into a dequeue – page 197 of the most recent "printing" on Leanpub. When I ran your code examples, I encountered a few hiccups:

  1. The extend function is not used in the code sample.
  2. The for loops in extend and the pushHead method (found in the return statement of Dequeue) declare the name-binding i with const instead of let; Thus, subsequent reassignments of i fail.

Additionally, I'm not sure what purpose INCREMENT serves. Because it is constant, it is not responsive to the state of the data structure. This results in sparse arrays at times.

Instead of merely pointing these issues out, I also attach a text document containing revisions to your code sample, which I believe implement a dequeue. I made two major revisions beyond addressing the issues I enumerate above:

  1. My queue has a method called expose which I found useful for debugging.
  2. I declare increment with let, and reassign it in the if block of the pushHead method.
    Finally, note that the format of the text document is .org, not .js. I used org mode's code blocks and the babel transpiler to display my REPLs output at the bottom of the document

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions