-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfronts.js
More file actions
45 lines (38 loc) · 859 Bytes
/
fronts.js
File metadata and controls
45 lines (38 loc) · 859 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
class Node {
constructor(value) {
this.value = value;
this.next = null;
}
}
// ADD FRONT
function addFront(head, value) {
const newNode = new Node(value);
newNode.next = head;
return newNode;
}
let head = new Node(1);
console.log("Original head value:", head.value);
head = addFront(head, 3);
console.log("The new head value is:", head.value);
console.log("The next node value is:", head.next.value);
// REMOVE FRONT
function removeFront(head) {
if(!head) {
return null;
}
const newHead = head.next;
head.next = null;
return newHead;
}
let head1 = new Node(1);
head1 = removeFront(head1);
console.log("New head value:" , head1);
// FRONT
function front(head) {
if(!head) {
return null;
}
return head.value;
}
let head2 = null;
console.log("Head value:", front(head2));