title: Implement sorting in linked list in JavaScript (bubble sort or another)
body: <p>I am trying to implement Bubble sort for a linked list in JavaScript. I was looking for similar questions but only found implementation in C ++ or Java. I would be grateful for your help.
  It would be great to do BubbleSort but if there are other sorting options, I will also be happy to see their implementation. I tried different options to implement sorting in the linked list but they didn't work.
  Now I just have methods that add elements in begin or end of the list.
  Below is the implementation of the list.</p>
  <p>LinkedListNode</p>
  <pre><code>export class LinkedListNode {
    public value;
    public prev;
    public next;
  
    constructor(value) {
      this.value = value;
      this.next = null;
      this.prev = null;
    }
  }
  </code></pre>
  <p>LinkedList</p>
  <pre><code>import { LinkedListNode } from './LinkedListNode';
  
  export class LinkedList {
    private head;
    private tail;
  
    addHeadNode = (value) =&gt; {
      const newLinkendListNode = new LinkedListNode(value);
  
      if (!this.head) {
        this.head = newLinkendListNode;
        this.tail = newLinkendListNode;
      } else {
        this.head.prev = newLinkendListNode;
        newLinkendListNode.next = this.head;
        this.head = newLinkendListNode;
      }
    };
  
    addTailNode = (value) =&gt; {
      const newLinkendListNode = new LinkedListNode(value);
  
      if (!this.tail) {
        this.head = newLinkendListNode;
        this.tail = newLinkendListNode;
      } else {
        this.tail.next = newLinkendListNode;
        newLinkendListNode.prev = this.tail;
        this.tail = newLinkendListNode;
      }
    };
  
    getByIndex = index =&gt; {
      let currentNode = this.head;
      let count = 0;
  
      while (currentNode) {
        if (count === index) {
          console.log(currentNode);
          return currentNode;
        }
        count++;
        currentNode = currentNode.next;
      }
      return -1;
    };
  }
  </code></pre>