Skip to content

Latest commit

 

History

History
32 lines (26 loc) · 551 Bytes

add.md

File metadata and controls

32 lines (26 loc) · 551 Bytes

Add

What we will do first is add a value to a Linked List.

class Node {
    constructor(data) {
        this.data = data
        this.next = null 
    }
}

class LinkedList {
    constructor(head) {
        this.head = head 
    }

    append = (value) => {
        const newNode = new Node(value) 
        let current = this.head 

        if (!this.head) {
            this.head = newNode 
            return 
        }

        while (current.next) {
            current = current.next
        }
        current.next = newNode
    }
}