Commit 6b1dcac6 authored by Brady James Garvin's avatar Brady James Garvin
Browse files

Updated code to use JavaScript modules.

parent 5e1b5ede
......@@ -4,6 +4,9 @@
"browser": true,
"jquery": true,
},
"parserOptions": {
"sourceType": "module",
},
"rules": {
"no-await-in-loop": "warn",
"no-compare-neg-zero": "warn",
......
......@@ -5,18 +5,12 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Basic Graph Search</title>
<script defer="true" src="libraries/jquery/jquery.min.js"></script>
<script defer="true" type="module" src="js/index.js"></script>
</head>
<body>
<div id="output"></div>
<script src="libraries/jquery/jquery.min.js"></script>
<script src="js/utility.js"></script>
<script src="js/stack.js"></script>
<script src="js/queue.js"></script>
<script src="js/priority_queue.js"></script>
<script src="js/graphs.js"></script>
<script src="js/inputs.js"></script>
<script src="js/index.js"></script>
</body>
</html>
/* exported DirectedGraph PuzzleGraph */
class WeightedEdge {
constructor(weight, destination) {
this.weight = weight;
......@@ -7,7 +5,7 @@ class WeightedEdge {
}
}
class DirectedGraph {
export class DirectedGraph {
constructor() {
this.incidences = new Map();
}
......@@ -24,7 +22,7 @@ class DirectedGraph {
}
}
class PuzzleGraph {
export class PuzzleGraph {
getIncidences(source) { // eslint-disable-line class-methods-use-this
const result = [];
for (let i = source.length; i--;) {
......
/* exported dfs bfs dijkstras */
/* globals BasicStack BasicQueue BasicPriorityQueue firstExample secondExample */
import './utility.js';
import {BasicStack} from './stack.js';
import {BasicQueue} from './queue.js';
import {BasicPriorityQueue} from './priority_queue.js';
import {firstExample, secondExample} from './inputs.js';
function print(value) {
$('#output').append($('<span></span>').text(value)).append('<br>');
}
function dfs(graph, source, destination) {
export function dfs(graph, source, destination) {
return []; // stub
}
function bfs(graph, source, destination) {
export function bfs(graph, source, destination) {
return []; // stub
}
function dijkstras(graph, source, destination) {
export function dijkstras(graph, source, destination) {
return []; // stub
}
......
/* exported firstExample secondExample */
/* globals DirectedGraph PuzzleGraph */
import {DirectedGraph, PuzzleGraph} from './graphs.js';
/* eslint-disable no-magic-numbers */
const firstExample = new DirectedGraph();
export const firstExample = new DirectedGraph();
firstExample.addIncidence('b', 9, 'e');
firstExample.addIncidence('f', 8, 'c');
firstExample.addIncidence('a', 7, 'c');
......@@ -14,4 +14,4 @@ firstExample.addIncidence('e', 2, 'f');
firstExample.addIncidence('c', 1, 'b');
firstExample.addIncidence('f', 0, 'd');
const secondExample = new PuzzleGraph();
export const secondExample = new PuzzleGraph();
/* exported BasicPriorityQueue */
import './utility.js';
class BasicPriorityQueue {
export class BasicPriorityQueue {
constructor() {
this.elements = [];
}
......
/* exported BasicQueue */
class BasicQueue {
export class BasicQueue {
constructor() {
this.elements = [];
this.head = 0;
......
/* exported BasicStack */
class BasicStack {
export class BasicStack {
constructor() {
this.elements = [];
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment