Skip to content

Commit 9d4349c

Browse files
authored
Merge branch 'master' into master
2 parents 81ea260 + fc0aba0 commit 9d4349c

File tree

3 files changed

+83
-90
lines changed

3 files changed

+83
-90
lines changed

maths/factorial.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,6 @@ function calcFactorial (num) {
4848
}
4949

5050
// Run `factorial` Function to find average of a list of numbers.
51-
/* global prompt */
52-
var num = prompt('Enter a number: ')
51+
52+
var num = console.log('Enter a number: ')
5353
console.log(calcFactorial(num))

maths/find_lcm.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
license: GPL-3.0 or later
44
55
Modified from:
6-
https://github.com/TheAlgorithms/Python/blob/master/maths/find_lcm.py
6+
https://github.com/TheAlgorithms/Python/blob/master/maths/findLcm.py
77
88
More about LCM:
99
https://en.wikipedia.org/wiki/Least_common_multiple

maths/graph.js

Lines changed: 80 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,88 @@
1-
// create a graph class
2-
class Graph {
3-
// defining vertex array and
4-
// adjacent list
5-
constructor(noOfVertices)
6-
{
7-
this.noOfVertices = noOfVertices;
8-
this.AdjList = new Map();
9-
}
10-
11-
// functions to be implemented
12-
13-
// addVertex(v)
14-
// addEdge(v, w)
15-
// printGraph()
16-
17-
// bfs(v)
18-
// dfs(v)
19-
}
1+
// create a graph class
2+
class Graph {
3+
// defining vertex array and
4+
// adjacent list
5+
constructor (noOfVertices) {
6+
this.noOfVertices = noOfVertices
7+
this.AdjList = new Map()
8+
}
209

21-
// add vertex to the graph
22-
addVertex(v)
23-
{
24-
// initialize the adjacent list with a
25-
// null array
26-
this.AdjList.set(v, []);
27-
}
10+
// functions to be implemented
2811

29-
// add edge to the graph
30-
addEdge(v, w)
31-
{
32-
// get the list for vertex v and put the
33-
// vertex w denoting edge between v and w
34-
this.AdjList.get(v).push(w);
35-
36-
// Since graph is undirected,
37-
// add an edge from w to v also
38-
this.AdjList.get(w).push(v);
39-
}
12+
// addVertex(v)
13+
// addEdge(v, w)
14+
// printGraph()
4015

16+
// bfs(v)
17+
// dfs(v)
4118

42-
// Prints the vertex and adjacency list
43-
printGraph()
44-
{
45-
// get all the vertices
46-
var get_keys = this.AdjList.keys();
47-
48-
// iterate over the vertices
49-
for (var i of get_keys)
50-
{
51-
// great the corresponding adjacency list
52-
// for the vertex
53-
var get_values = this.AdjList.get(i);
54-
var conc = "";
55-
56-
// iterate over the adjacency list
57-
// concatenate the values into a string
58-
for (var j of get_values)
59-
conc += j + " ";
60-
61-
// print the vertex and its adjacency list
62-
console.log(i + " -> " + conc);
63-
}
64-
}
19+
// add vertex to the graph
20+
addVertex (v) {
21+
// initialize the adjacent list with a
22+
// null array
23+
24+
this.AdjList.set(v, [])
25+
}
26+
27+
// add edge to the graph
28+
addEdge (v, w) {
29+
// get the list for vertex v and put the
30+
// vertex w denoting edge between v and w
31+
this.AdjList.get(v).push(w)
32+
33+
// Since graph is undirected,
34+
// add an edge from w to v also
35+
this.AdjList.get(w).push(v)
36+
}
6537

38+
// Prints the vertex and adjacency list
39+
printGraph () {
40+
// get all the vertices
41+
const getKeys = this.AdjList.keys()
6642

43+
// iterate over the vertices
44+
for (const i of getKeys) {
45+
// great the corresponding adjacency list
46+
// for the vertex
47+
const getValues = this.AdjList.get(i)
48+
let conc = ''
49+
50+
// iterate over the adjacency list
51+
// concatenate the values into a string
52+
for (const j of getValues) {
53+
conc += j + ' '
54+
}
55+
56+
// print the vertex and its adjacency list
57+
console.log(i + ' -> ' + conc)
58+
}
59+
}
60+
}
6761
// Example
68-
var graph = new Graph(6);
69-
var vertices = [ 'A', 'B', 'C', 'D', 'E', 'F' ];
70-
71-
// adding vertices
72-
for (var i = 0; i < vertices.length; i++) {
73-
g.addVertex(vertices[i]);
74-
}
75-
76-
// adding edges
77-
g.addEdge('A', 'B');
78-
g.addEdge('A', 'D');
79-
g.addEdge('A', 'E');
80-
g.addEdge('B', 'C');
81-
g.addEdge('D', 'E');
82-
g.addEdge('E', 'F');
83-
g.addEdge('E', 'C');
84-
g.addEdge('C', 'F');
85-
86-
// prints all vertex and
87-
// its adjacency list
88-
// A -> B D E
89-
// B -> A C
90-
// C -> B E F
91-
// D -> A E
92-
// E -> A D F C
93-
// F -> E C
94-
g.printGraph();
62+
const graph = new Graph(6)
63+
const vertices = ['A', 'B', 'C', 'D', 'E', 'F']
64+
65+
// adding vertices
66+
for (let i = 0; i < vertices.length; i++) {
67+
graph.addVertex(vertices[i])
68+
}
69+
70+
// adding edges
71+
graph.addEdge('A', 'B')
72+
graph.addEdge('A', 'D')
73+
graph.addEdge('A', 'E')
74+
graph.addEdge('B', 'C')
75+
graph.addEdge('D', 'E')
76+
graph.addEdge('E', 'F')
77+
graph.addEdge('E', 'C')
78+
graph.addEdge('C', 'F')
9579

80+
// prints all vertex and
81+
// its adjacency list
82+
// A -> B D E
83+
// B -> A C
84+
// C -> B E F
85+
// D -> A E
86+
// E -> A D F C
87+
// F -> E C
88+
graph.printGraph()

0 commit comments

Comments
 (0)