Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linked list shift #168

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,12 @@ This book will teach you the basics of programming and Javascript. Whether you a

![](./assets/intro.png)

JavaScript (_JS for short_) is the programming language that enables web pages to respond to user interaction beyond the basic level. It was created in 1995, and is today one of the most famous and used programming languages.
JavaScript is the world's most popular programming language.

JavaScript is the programming language of the Web.

JavaScript is easy to learn.

JavaScript, often abbreviated JS, is a programming language that is one of the core technologies of the World Wide Web, alongside HTML and CSS. As of 2022, 98% of websites use JavaScript on the client side for webpage behavior, often incorporating third-party libraries.

Do not confuse JavaScript with the Java programming language. Both "Java" and "JavaScript" are trademarks or registered trademarks of Oracle in the U.S. and other countries. However, the two programming languages have very different syntax, semantics, and use.
8 changes: 8 additions & 0 deletions arrays/foreach.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Looping with Foreach

The forEach() method executes a provided function once for each array element.

```javascript
var arr = ["one", "two", "three"];

arr.forEach(e => console.log(e));
8 changes: 8 additions & 0 deletions arrays/join.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#Joining

The .Join() method, makes an array turn into a string and joining it all together.

```javascript
var array ["one", "two", "three", "four"];

console.log(array.join(" "));
11 changes: 11 additions & 0 deletions arrays/looping.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#Looping

With Looping, you can access any point in an array with an increment, making you go through every item in the array.

```javascript
var array = [1, 2, 3, 4, 5];

for (let i = 0; i < array.length(); i++)
{
console.log(array[i]);
}
10 changes: 10 additions & 0 deletions arrays/methods.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Methods

Using methods on an array alters an array in some sort of way.

```javascript
var array = [1, 2, 3];

array = array.join('');

console.log(array);
10 changes: 10 additions & 0 deletions arrays/pop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Pop

The pop() method removes the last element from an array and returns that element. This method changes the length of the array.

```javascript
var arr = ["one", "two", "three", "four", "five"];

arr.pop();

console.log(arr);
10 changes: 10 additions & 0 deletions arrays/push.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Push

You can push certain items to an array making the last index the item you just added.

```javascript
var array = [1, 2, 3];

array.push(4);

console.log(array);
10 changes: 10 additions & 0 deletions arrays/shift.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Shift

What Shift does to an array is delete the first index of that array and move all indexes to the left.

```javascript
var array = [1, 2, 3];

array.shift();

console.log(array);
10 changes: 10 additions & 0 deletions arrays/sort.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Sorting an Array

The sort() method sorts the items of an array in a specific order (ascending or descending).

```javascript
var city = ["California", "Barcelona", "Paris", "Kathmandu"];

var sortedArray = city.sort();

console.log(sortedArray);
8 changes: 8 additions & 0 deletions arrays/spread.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#Spread Operator

With the Spread Operator, it allows us to quickly copy all or part of an existing array or object into another array or object.

```javascript
var arr = [1, 2, 3, 4, 5];

console.log(...arr);
16 changes: 16 additions & 0 deletions boolean/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Boolean

A JavaScript Boolean represents one of two values: true or false.

```javascript
var equalsHeads = false;

if (equalsHeads === true)
{
console.log("coin is heads");
}

else if (equalsHeads === false)
{
console.log("coin is tails");
}
13 changes: 13 additions & 0 deletions linked list/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Linked Lists

In all programming languages, there are data structures. One of these data structures are called Linked Lists. There is no built in method or function for Linked Lists in Javascript so you will have to implement it yourself.

A Linked List is very similar to a normal array in Javascript, it just acts a little bit differently.

In this chapter, we will go over the different ways we can implement a Linked List.

Here's an example of a Linked List:

```
["one", "two", "three", "four"]
```
32 changes: 32 additions & 0 deletions linked list/add.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Add

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

```js
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
}
}
25 changes: 25 additions & 0 deletions linked list/pop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Pop


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

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

pop = () => {
let current = this.head

while (current.next.next) {
current = current.next
}
current.next = current.next.next
}
}
29 changes: 29 additions & 0 deletions linked list/prepend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Add

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

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

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

prepend = (value) => {
const newNode = new Node(value)

if (!this.head) {
this.head = newNode
}
else {
newNode.next = this.head
this.head = newNode
}
}
}
21 changes: 21 additions & 0 deletions linked list/shift.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Shift

What we will do first is remove the first element of the Linked List.

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

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

shift = () => {
this.head = this.head.next
}
}