trekhleb / trekhleb/javascript-algorithms

Maybe there are some redundent code in Doubly-Linked-List

Aperta
#655 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Lingua principale
JavaScript
Stelle
197k
Fork
31k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

    reverse() {
        let node = this.head,
            previous = null,
            next = null;

        while (node) {
            next = node.next;
            console.log(previous?.value);
            previous = node.previous;
            console.log(previous?.value);
            node.next = previous;            
            node.previous = next;

            previous = node;
            node = next;
        }
        this.tail = this.head;
        this.head = previous;
        return this;
    }

I think the code previous = node.previous; in while loop is redundent code. I try this code and the previous.vaule always get a same value.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Start with the Doubly-Linked-List reverse() implementation shown in the issue and trace the previous, node, and next assignments through the loop. Determine whether the questioned assignment changes the result or is redundant, then confirm that the reversal behavior remains correct after any change.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
javascript
Ambito
data
Tipo di issue
Refactoring
Difficoltà
2/5
Tempo stimato
1-3 ore
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.