Skip to content

Commit efc4c40

Browse files
committed
learn about DSA
1 parent 7b10d64 commit efc4c40

File tree

4 files changed

+48
-1
lines changed

4 files changed

+48
-1
lines changed

Diff for: day9.js renamed to Array/day9.js

File renamed without changes.

Diff for: Array/tempCodeRunnerFile.js

-1
This file was deleted.

Diff for: link-list/day10.js

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// ! DSA in JavaScript day 10
2+
3+
// Todo: Link List
4+
5+
class Node {
6+
constructor(value) {
7+
this.head = value;
8+
this.next = null;
9+
}
10+
}
11+
12+
class LinkedList {
13+
constructor(value) {
14+
this.head = new Node(value);
15+
this.teal = this.head;
16+
this.length = 1;
17+
}
18+
19+
push(value) {
20+
let newNode = new Node(value);
21+
if (!this.head) {
22+
this.head = newNode;
23+
this.teal = newNode;
24+
}
25+
26+
this.teal.next = newNode;
27+
this.teal = newNode;
28+
this.length++;
29+
}
30+
}
31+
32+
const MyList = new LinkedList(1);
33+
34+
MyList.push(10);
35+
console.log(MyList);

Diff for: test/two-sum.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// ! Two Sum
2+
3+
function TwoSum(array, sum) {
4+
for (let i = 0; i < array.length; i++) {
5+
for (let j = 1; j < array.length; j++) {
6+
if (array[i] + array[j] === sum) {
7+
return [i, j];
8+
}
9+
}
10+
}
11+
}
12+
13+
console.log(TwoSum([2, 7, 4, 8], 15));

0 commit comments

Comments
 (0)