Skip to content

Commit 339a2fd

Browse files
committed
Sorting Algorithms HW Update Bubble Sort
1 parent 3b558eb commit 339a2fd

File tree

6 files changed

+93
-1
lines changed

6 files changed

+93
-1
lines changed

ExampleProject/app.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
var msg = "Hello World";
2+
console.log(msg);
3+
4+
const prompt = require{'prompt-sync'} {};
5+
const name = prompt("What is your name?");
6+
console.log("Hey there $(name)");

ExampleProject/package-lock.json

+43
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ExampleProject/package.json

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "exampleproject",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"keywords": [],
10+
"author": "",
11+
"license": "ISC",
12+
"dependencies": {
13+
"prompt-sync": "^4.2.0"
14+
}
15+
}

examples/chapter01_02/02-Variables.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ console.log('myName: ' + myName);
1515
console.log('trueValue: ' + trueValue);
1616
console.log('price: ' + price);
1717
console.log('nullVar: ' + nullVar);
18-
console.log('und: ' + und);
18+
console.log('und: ' + und);
1919

2020
// ******* Variable Scope
2121

examples/chapter13/01-BubbleSort.html

+8
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,13 @@
77
<body>
88
<script src="./../PacktDataStructuresAlgorithms.min.js"></script>
99
<script src="01-BubbleSort.js"></script>
10+
11+
<h2>Bubble Sort</h2>
12+
13+
<form>
14+
<label for = "numberOfValues">Number of values:</label><br>
15+
<input type = "text" id = "numberOfValues" name = "numberOfValues" value = "0"><br>
16+
<input type = "button" value = "Submit" onCLick = "callJavaScript()">
17+
</form>
1018
</body>
1119
</html>

examples/chapter13/01-BubbleSort.js

+20
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
const { bubbleSort } = PacktDataStructuresAlgorithms;
22

3+
function RunBubbleSort(){
4+
var valuepicked = document.getElementById('numberOfValues').value;
5+
if (valuepicked > 0) {
6+
const array = bubbleSort(createNonSortedArray(valuepicked));
7+
console.log(array);
8+
} else {
9+
console.error("");
10+
alert("invalid input");
11+
}
12+
}
13+
314
function createNonSortedArray(){
415
var array = [];
516
for (let i = 5; i > 0; i--){
@@ -8,5 +19,14 @@ function createNonSortedArray(){
819
return array;
920
}
1021

22+
function createNonSortedArray(Parameter){
23+
var array = [];
24+
for (let i = Parameter; i > 0; i--){
25+
array.push(i);
26+
}
27+
return array;
28+
}
29+
30+
1131
const array = bubbleSort(createNonSortedArray());
1232
console.log(array);

0 commit comments

Comments
 (0)