Skip to content

Commit 529f4be

Browse files
committed
del semicolon sign
1 parent 65c14b6 commit 529f4be

File tree

4 files changed

+105
-105
lines changed

4 files changed

+105
-105
lines changed

bubble-sort/javascript/bubble-sort.js

+25-25
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
let firstArray = [];
2-
let secondArray = [1, 1, 19, 4, 5];
3-
let thirdArray = [-1, 2, 4, -5, 10];
4-
let fourthArray = [-1, -5, -12, -2, 0];
1+
let firstArray = []
2+
let secondArray = [1, 1, 19, 4, 5]
3+
let thirdArray = [-1, 2, 4, -5, 10]
4+
let fourthArray = [-1, -5, -12, -2, 0]
55

66
// Generate an array with random numbers
77
for(let i = 0; i < 5; i++) {
8-
firstArray.push(Math.round(Math.random() * 100));
8+
firstArray.push(Math.round(Math.random() * 100))
99
}
1010

11-
console.log(`Before sort 1 array: ${firstArray}\nBefore sort 2 array: ${secondArray}\nBefore sort 3 array: ${thirdArray}\nBefore sort 4 array: ${fourthArray}`);
11+
console.log(`Before sort 1 array: ${firstArray}\nBefore sort 2 array: ${secondArray}\nBefore sort 3 array: ${thirdArray}\nBefore sort 4 array: ${fourthArray}`)
1212

1313
// First concept
1414
function bubbleSort (arr) {
1515
for(let i = arr.length - 1; i > 0; i--) {
1616
for (let j = 0; j < i; j++) {
1717
if(arr[j] > arr[j + 1]) {
18-
let temp = arr[j];
19-
arr[j] = arr[j + 1];
20-
arr[j + 1] = temp;
18+
let temp = arr[j]
19+
arr[j] = arr[j + 1]
20+
arr[j + 1] = temp
2121
}
2222
}
2323
}
@@ -26,30 +26,30 @@ function bubbleSort (arr) {
2626
// Second concept
2727
function bubbleSortSecondConcept (arr) {
2828
do {
29-
swapped = false;
30-
console.log(arr);
29+
swapped = false
30+
console.log(arr)
3131
arr.forEach((item, index) => {
3232
if (item > arr[index + 1]) {
3333
// Save the value to a variable so we don't lose it
34-
let temp = item;
35-
arr[index] = arr[index + 1];
36-
arr[index + 1] = temp;
37-
swapped = true;
34+
let temp = item
35+
arr[index] = arr[index + 1]
36+
arr[index + 1] = temp
37+
swapped = true
3838
}
3939
})
40-
} while (swapped);
40+
} while (swapped)
4141
}
4242

4343
// Test for first concept
44-
bubbleSort(firstArray);
45-
bubbleSort(secondArray);
46-
bubbleSort(thirdArray);
47-
bubbleSort(fourthArray);
44+
bubbleSort(firstArray)
45+
bubbleSort(secondArray)
46+
bubbleSort(thirdArray)
47+
bubbleSort(fourthArray)
4848

4949
// Test for first concept
50-
bubbleSortSecondConcept(firstArray);
51-
bubbleSortSecondConcept(secondArray);
52-
bubbleSortSecondConcept(thirdArray);
53-
bubbleSortSecondConcept(fourthArray);
50+
bubbleSortSecondConcept(firstArray)
51+
bubbleSortSecondConcept(secondArray)
52+
bubbleSortSecondConcept(thirdArray)
53+
bubbleSortSecondConcept(fourthArray)
5454

55-
console.log(`After sort 1 array: ${firstArray}\nAfter sort 2 array: ${secondArray}\nAfter sort 3 array: ${thirdArray}\nAfter sort 4 array: ${fourthArray}`);
55+
console.log(`After sort 1 array: ${firstArray}\nAfter sort 2 array: ${secondArray}\nAfter sort 3 array: ${thirdArray}\nAfter sort 4 array: ${fourthArray}`)
+30-30
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,78 @@
1-
let firstArray = [];
2-
let secondArray = [1, 1, 19, 4, 5];
3-
let thirdArray = [-1, 2, 4, -5, 10];
4-
let fourthArray = [-1, -5, -12, -2, 0];
5-
let fifthArray =[ 37, 23, 0, 17, 12, 72, 31, 46, 100, 88, 54];
1+
let firstArray = []
2+
let secondArray = [1, 1, 19, 4, 5]
3+
let thirdArray = [-1, 2, 4, -5, 10]
4+
let fourthArray = [-1, -5, -12, -2, 0]
5+
let fifthArray =[ 37, 23, 0, 17, 12, 72, 31, 46, 100, 88, 54]
66

77
// Generate an array with random numbers
88
for(let i = 0; i < 5; i++) {
9-
firstArray.push(Math.round(Math.random() * 100));
9+
firstArray.push(Math.round(Math.random() * 100))
1010
}
1111

12-
console.log(`Before sort 1 array: ${firstArray}\nBefore sort 2 array: ${secondArray}\nBefore sort 3 array: ${thirdArray}\nBefore sort 4 array: ${fourthArray}\nBefore binary sort 5 array: ${fifthArray}`);
12+
console.log(`Before sort 1 array: ${firstArray}\nBefore sort 2 array: ${secondArray}\nBefore sort 3 array: ${thirdArray}\nBefore sort 4 array: ${fourthArray}\nBefore binary sort 5 array: ${fifthArray}`)
1313

1414
function insertionSort(arr) {
15-
let key, j;
15+
let key, j
1616
for (let i = 1; i < arr.length; i++) {
17-
key = arr[i];
18-
j = i - 1;
17+
key = arr[i]
18+
j = i - 1
1919
/* Move elements of arr[0..i-1], that are
2020
greater than key, to one position ahead
2121
of their current position */
2222
while (j >= 0 && arr[j] > key) {
23-
arr[j + 1] = arr[j];
24-
j = j - 1;
23+
arr[j + 1] = arr[j]
24+
j = j - 1
2525
}
26-
arr[j + 1] = key;
26+
arr[j + 1] = key
2727
}
28-
return arr;
28+
return arr
2929
}
3030

3131
// binary insertion sort
3232
function binarySearch(a, item, low, high) {
3333
if (high <= low)
34-
return (item > a[low]) ? (low + 1) : low;
34+
return (item > a[low]) ? (low + 1) : low
3535

36-
mid = Math.floor((low + high) / 2);
36+
mid = Math.floor((low + high) / 2)
3737

3838
if(item == a[mid])
39-
return mid + 1;
39+
return mid + 1
4040

4141
if(item > a[mid])
42-
return binarySearch(a, item, mid + 1, high);
42+
return binarySearch(a, item, mid + 1, high)
4343

44-
return binarySearch(a, item, low, mid - 1);
44+
return binarySearch(a, item, low, mid - 1)
4545
}
4646

4747
function binaryInsertionSort(arr) {
4848
for (let i = 1; i < arr.length; i++) {
49-
let j = i - 1;
50-
let x = arr[i];
49+
let j = i - 1
50+
let x = arr[i]
5151

5252
// Find location to insert
5353
// using binary search
54-
let loc = Math.abs(binarySearch(arr, x, 0, j));
54+
let loc = Math.abs(binarySearch(arr, x, 0, j))
5555

5656
// Shifting array to one
5757
// location right
5858

5959
while (j >= loc) {
60-
arr[j + 1] = arr[j];
61-
j--;
60+
arr[j + 1] = arr[j]
61+
j--
6262
}
6363

6464
// Placing element at its
6565
// correct location
66-
arr[j+1] = x;
66+
arr[j+1] = x
6767
}
6868
}
6969

7070
// Test
71-
insertionSort(firstArray);
72-
insertionSort(secondArray);
73-
insertionSort(thirdArray);
74-
insertionSort(fourthArray);
71+
insertionSort(firstArray)
72+
insertionSort(secondArray)
73+
insertionSort(thirdArray)
74+
insertionSort(fourthArray)
7575

7676
binaryInsertionSort(fifthArray)
7777

78-
console.log(`After sort 1 array: ${firstArray}\nAfter sort 2 array: ${secondArray}\nAfter sort 3 array: ${thirdArray}\nAfter sort 4 array: ${fourthArray}\nAfter binary sort 5 array: ${fifthArray}`);
78+
console.log(`After sort 1 array: ${firstArray}\nAfter sort 2 array: ${secondArray}\nAfter sort 3 array: ${thirdArray}\nAfter sort 4 array: ${fourthArray}\nAfter binary sort 5 array: ${fifthArray}`)

quick-sort/javascript/quick-sort.js

+27-27
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,55 @@
1-
let firstArray = [];
2-
let secondArray = [1, 1, 19, 4, 5];
3-
let thirdArray = [-1, 2, 4, -5, 10];
4-
let fourthArray = [-1, -5, -12, -2, 0];
1+
let firstArray = []
2+
let secondArray = [1, 1, 19, 4, 5]
3+
let thirdArray = [-1, 2, 4, -5, 10]
4+
let fourthArray = [-1, -5, -12, -2, 0]
55

66
// Generate an array with random numbers
77
for(let i = 0; i < 5; i++) {
8-
firstArray.push(Math.round(Math.random() * 100));
8+
firstArray.push(Math.round(Math.random() * 100))
99
}
1010

11-
console.log(`Before sort 1 array: ${firstArray}\nBefore sort 2 array: ${secondArray}\nBefore sort 3 array: ${thirdArray}\nBefore sort 4 array: ${fourthArray}`);
11+
console.log(`Before sort 1 array: ${firstArray}\nBefore sort 2 array: ${secondArray}\nBefore sort 3 array: ${thirdArray}\nBefore sort 4 array: ${fourthArray}`)
1212

1313
// First concept
1414
function firstQuickSort(arr) {
15-
if (arr.length < 2) return arr;
16-
let pivot = arr[0];
17-
const left = [];
18-
const right = [];
15+
if (arr.length < 2) return arr
16+
let pivot = arr[0]
17+
const left = []
18+
const right = []
1919

2020
for (let i = 1; i < arr.length; i++) {
2121
if (pivot > arr[i]) {
22-
left.push(arr[i]);
22+
left.push(arr[i])
2323
} else {
24-
right.push(arr[i]);
24+
right.push(arr[i])
2525
}
2626
}
27-
return firstQuickSort(left).concat(pivot, firstQuickSort(right));
27+
return firstQuickSort(left).concat(pivot, firstQuickSort(right))
2828
}
2929

3030
// Second concept
3131
function secondQuickSort(arr) {
32-
if (arr.length < 2) return arr;
33-
let min = 1;
34-
let max = arr.length - 1;
35-
let rand = Math.floor(min + Math.random() * (max + 1 - min));
36-
let pivot = arr[rand];
37-
const left = [];
38-
const right = [];
39-
arr.splice(arr.indexOf(pivot), 1);
40-
arr = [pivot].concat(arr);
32+
if (arr.length < 2) return arr
33+
let min = 1
34+
let max = arr.length - 1
35+
let rand = Math.floor(min + Math.random() * (max + 1 - min))
36+
let pivot = arr[rand]
37+
const left = []
38+
const right = []
39+
arr.splice(arr.indexOf(pivot), 1)
40+
arr = [pivot].concat(arr)
4141
for (let i = 1; i < arr.length; i++) {
4242
if (pivot > arr[i]) {
43-
left.push(arr[i]);
43+
left.push(arr[i])
4444
} else {
45-
right.push(arr[i]);
45+
right.push(arr[i])
4646
}
4747
}
48-
return secondQuickSort(left).concat(pivot, secondQuickSort(right));
48+
return secondQuickSort(left).concat(pivot, secondQuickSort(right))
4949
}
5050

5151

5252
// Test
53-
console.log(`After first sort 1 array: ${firstQuickSort(firstArray)}\nAfter first sort 2 array: ${firstQuickSort(secondArray)}\nAfter first sort 3 array: ${firstQuickSort(thirdArray)}\nAfter first sort 4 array: ${firstQuickSort(fourthArray)}`);
53+
console.log(`After first sort 1 array: ${firstQuickSort(firstArray)}\nAfter first sort 2 array: ${firstQuickSort(secondArray)}\nAfter first sort 3 array: ${firstQuickSort(thirdArray)}\nAfter first sort 4 array: ${firstQuickSort(fourthArray)}`)
5454

55-
console.log(`After second sort 1 array: ${secondQuickSort(firstArray)}\nAfter second sort 2 array: ${secondQuickSort(secondArray)}\nAfter second sort 3 array: ${secondQuickSort(thirdArray)}\nAfter second sort 4 array: ${secondQuickSort(fourthArray)}`);
55+
console.log(`After second sort 1 array: ${secondQuickSort(firstArray)}\nAfter second sort 2 array: ${secondQuickSort(secondArray)}\nAfter second sort 3 array: ${secondQuickSort(thirdArray)}\nAfter second sort 4 array: ${secondQuickSort(fourthArray)}`)
+23-23
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
1-
let firstArray = [];
2-
let secondArray = [1, 1, 19, 4, 5];
3-
let thirdArray = [-1, 2, 4, -5, 10];
4-
let fourthArray = [-1, -5, -12, -2, 0];
5-
let fifthArray = [4, 5, 3, 2, 4, 1];
1+
let firstArray = []
2+
let secondArray = [1, 1, 19, 4, 5]
3+
let thirdArray = [-1, 2, 4, -5, 10]
4+
let fourthArray = [-1, -5, -12, -2, 0]
5+
let fifthArray = [4, 5, 3, 2, 4, 1]
66

77
// Generate an array with random numbers
88
for(let i = 0; i < 5; i++) {
9-
firstArray.push(Math.round(Math.random() * 100));
9+
firstArray.push(Math.round(Math.random() * 100))
1010
}
1111

12-
console.log(`Before sort 1 array: ${firstArray}\nBefore sort 2 array: ${secondArray}\nBefore sort 3 array: ${thirdArray}\nBefore sort 4 array: ${fourthArray}\nBefore stable sort 5 array: ${fifthArray}`);
12+
console.log(`Before sort 1 array: ${firstArray}\nBefore sort 2 array: ${secondArray}\nBefore sort 3 array: ${thirdArray}\nBefore sort 4 array: ${fourthArray}\nBefore stable sort 5 array: ${fifthArray}`)
1313

1414
// Simple selection sort
1515
function selectionSort(arr) {
1616
for(let i = 0; i < arr.length - 1; i++) {
17-
let indexMin = i;
17+
let indexMin = i
1818

1919
for(let j = i + 1; j < arr.length; j++) {
2020
if(arr[indexMin] > arr[j]) {
21-
indexMin = j;
21+
indexMin = j
2222
}
2323
}
2424
if(indexMin !== i) {
25-
[arr[i], arr[indexMin]] = [arr[indexMin], arr[i]];
25+
[arr[i], arr[indexMin]] = [arr[indexMin], arr[i]]
2626
}
2727
}
28-
return arr;
28+
return arr
2929
}
3030

3131
// Stable selection sort
@@ -37,29 +37,29 @@ function stableSelectionSort(arr) {
3737

3838
// Find minimum element from
3939
// arr[i] to arr[n - 1].
40-
let min = i;
40+
let min = i
4141
for (let j = i + 1; j < arr.length; j++) {
4242
if (arr[min] > arr[j]) {
43-
min = j;
43+
min = j
4444
}
4545
}
4646
// Move minimum element at current i.
47-
let key = arr[min];
47+
let key = arr[min]
4848
while (min > i) {
49-
arr[min] = arr[min - 1];
50-
min--;
49+
arr[min] = arr[min - 1]
50+
min--
5151
}
52-
arr[i] = key;
52+
arr[i] = key
5353
}
5454
}
5555

5656
// Test for simple selection sort
57-
selectionSort(firstArray);
58-
selectionSort(secondArray);
59-
selectionSort(thirdArray);
60-
selectionSort(fourthArray);
57+
selectionSort(firstArray)
58+
selectionSort(secondArray)
59+
selectionSort(thirdArray)
60+
selectionSort(fourthArray)
6161

6262
// Test for stable selection sort
63-
stableSelectionSort(fifthArray);
63+
stableSelectionSort(fifthArray)
6464

65-
console.log(`After sort 1 array: ${firstArray}\nAfter sort 2 array: ${secondArray}\nAfter sort 3 array: ${thirdArray}\nAfter sort 4 array: ${fourthArray}\nAfter stable sort 5 array: ${fifthArray}`);
65+
console.log(`After sort 1 array: ${firstArray}\nAfter sort 2 array: ${secondArray}\nAfter sort 3 array: ${thirdArray}\nAfter sort 4 array: ${fourthArray}\nAfter stable sort 5 array: ${fifthArray}`)

0 commit comments

Comments
 (0)