GithubHelp home page GithubHelp logo

chazkondo / js-linked-list Goto Github PK

View Code? Open in Web Editor NEW

This project forked from devleague/js-linked-list

0.0 0.0 0.0 115 KB

an exercise in creating linked list data structure

HTML 0.43% CSS 0.99% JavaScript 98.58%

js-linked-list's Introduction

Linked List - An Abstract Data Type

We will be creating a module that helps us generate a Linked List. A linked list is a data structure that contains nodes. Each node has a value and a next property. The value property contains some data that a user-defined when the node was created. The next property points to the next node in the list, ergo this is how the nodes are linked.

The last node in a Linked List will have a null value for the next property.

Linked List Example

{
  value: 'Ready Player One',
  next: {
    value: '1982',
    next: {
      value: 'Neuromancer',
      next: {
        value: 'Snow Crash',
        next: null
      }
    }
  }
}

Methods

getHead()

Returns the value of the first node of the list

linkedListExample.getHead(); // returns a node object...
{
  value: 'Ready Player One'
  next: { ... }
}

getTail()

Returns the value of the last node of a list.

linkedListExample.getTail(); // returns a node object...
{
  value: 'Snow Crash',
  next: null
}

add(Value)

Takes in any data value and adds a new node to the end of a list. Returns the new node that was created.

linkedListExample.add('The Stranger'); // returns the newly created and appended node...
{
  value: 'The Stranger',
  next: null
}

get(Number)

Takes in a Number value and searches for the Nth node in a list and returns that node

linkedListExample.get(2); // returns a node object...
{
  value: 'Neuromancer',
  next: { ... }
}

remove(Number)

Takes in a Number value and searches for the Nth node removes it from the list. Should return false if the the position is outside the length of the list.

linkedListExample.remove(3);

insert(Value, Number)

Inserts the specified element at the specified position in this list. Shifts the element currently at that position (if any) and any subsequent elements to the right.

Getting Started

  1. Fork this repository and clone it from your personal GitHub Account
  2. In the Terminal, navigate to the newly created folder for this repository.
  3. Install dependencies by running the command: npm install
  4. Run tests by running the command: npm test
  5. Your work will be one in the file named: linkedList.js
  6. Pay attention to the tests for hints on what Method names it expects.
  7. There are no stub descriptions in this exercise.
  8. Make your tests pass!

js-linked-list's People

Contributors

sgnl avatar jaywon avatar theremix avatar joekarlsson avatar nakaz avatar nolsky avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.