Guest User

Untitled

a guest
May 20th, 2018
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.29 KB | None | 0 0
  1. insertAt(data, index) {
  2. if (!this.head) {
  3. this.head = new Node(data)
  4. return;
  5. }
  6. if (index === 0) {
  7. this.head = new Node(data, this.head)
  8. return;
  9. }
  10. const previous = this.getAt(index - 1) || this.getLast()
  11. const node = new Node(data, previous.next)
  12. previous.next = node
  13. }
Add Comment
Please, Sign In to add comment