Skip to content

Commit 91e1bcd

Browse files
authored
Modify Tests in Javascript (#4705)
1 parent 150ef76 commit 91e1bcd

File tree

14 files changed

+73
-75
lines changed

14 files changed

+73
-75
lines changed

archive/j/javascript/convex-hull.js

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,30 @@
66
*/
77
function convexHull(points) {
88
function orientation(p, q, r) {
9-
const val = (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y)
10-
if (val === 0) return 0
11-
return val > 0 ? 1 : -1
9+
const val = (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);
10+
if (val === 0) return 0;
11+
return val > 0 ? 1 : -1;
1212
}
1313

1414
const n = points.length
15-
if (n < 3) return points
15+
if (n < 3) return points;
1616

17-
let minPointIndex = 0
17+
let minPointIndex = 0;
1818
for (let i = 0; i < n; i++) {
1919
if (
2020
(points[i].y < points[minPointIndex].y) ||
2121
(points[i].y == points[minPointIndex].y && points[i].x < points[minPointIndex].x)
2222
) {
23-
minPointIndex = i
23+
minPointIndex = i;
2424
}
2525
}
2626
const sortedPoints = [...points].sort((a, b) => {
27-
const angleA = Math.atan2(a.y - points[minPointIndex].y, a.x - points[minPointIndex].x)
28-
const angleB = Math.atan2(b.y - points[minPointIndex].y, b.x - points[minPointIndex].x)
29-
return angleA - angleB
27+
const angleA = Math.atan2(a.y - points[minPointIndex].y, a.x - points[minPointIndex].x);
28+
const angleB = Math.atan2(b.y - points[minPointIndex].y, b.x - points[minPointIndex].x);
29+
return angleA - angleB;
3030
})
3131

32-
const convexHull = [sortedPoints[0], sortedPoints[1]]
32+
const convexHull = [sortedPoints[0], sortedPoints[1]];
3333

3434
for (let i = 2; i < n; i++) {
3535
while (
@@ -40,12 +40,12 @@ function convexHull(points) {
4040
sortedPoints[i]
4141
) !== -1
4242
) {
43-
convexHull.pop()
43+
convexHull.pop();
4444
}
45-
convexHull.push(sortedPoints[i])
45+
convexHull.push(sortedPoints[i]);
4646
}
4747

48-
return convexHull
48+
return convexHull;
4949
}
5050

5151
/**
@@ -56,11 +56,11 @@ function convexHull(points) {
5656
*/
5757
function main(inputX, inputY) {
5858
if (inputX == undefined || inputY == undefined){
59-
inputX = " "
60-
inputY = " "
59+
inputX = " ";
60+
inputY = " ";
6161
}
62-
const xArray = inputX.split(",").map(Number)
63-
const yArray = inputY.split(",").map(Number)
62+
const xArray = inputX.split(",").map(Number);
63+
const yArray = inputY.split(",").map(Number);
6464

6565
if (
6666
xArray.length < 3 ||
@@ -70,17 +70,17 @@ function main(inputX, inputY) {
7070
) {
7171
console.log(
7272
'Usage: please provide at least 3 x and y coordinates as separate lists (e.g. "100, 440, 210")'
73-
)
74-
return
73+
);
74+
return;
7575
}
7676

77-
const points = xArray.map((x, i) => ({ x, y: yArray[i] }))
77+
const points = xArray.map((x, i) => ({ x, y: yArray[i] }));
7878

79-
const convexHullResult = convexHull(points)
80-
convexHullResult.forEach((point) => console.log(`(${point.x}, ${point.y})`))
79+
const convexHullResult = convexHull(points);
80+
convexHullResult.forEach((point) => console.log(`(${point.x}, ${point.y})`));
8181
}
8282

8383
// Run the executable function with command-line arguments
84-
const inputX = process.argv[2]
85-
const inputY = process.argv[3]
86-
main(inputX, inputY)
84+
const inputX = process.argv[2];
85+
const inputY = process.argv[3];
86+
main(inputX, inputY);

archive/j/javascript/dijkstra.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,4 @@ function main() {
8484
console.log(dijkstra(src, des, n));
8585
}
8686

87-
main()
87+
main();

archive/j/javascript/factorial.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ function factorial(num) {
77
let product = 1;
88
if ( num > 1 ) {
99
for ( let i = 2; i <= num; i++ ) {
10-
product *= i
10+
product *= i;
1111
}
1212
}
13-
return product
13+
return product;
1414
}
1515

1616
/**
@@ -24,36 +24,36 @@ function main(input) {
2424

2525
// No input
2626
if ( !input ) {
27-
console.log(usage)
28-
return
27+
console.log(usage);
28+
return;
2929
}
3030

3131
/**
3232
* If we remove all the integer characters from the input and are left with
3333
* an empty string, then we have a valid integer.
3434
*/
35-
const inputValidation = input.replace(/[0-9]/g,'')
35+
const inputValidation = input.replace(/[0-9]/g,'');
3636

3737
if ( inputValidation === '' ) {
3838
// Valid integer
39-
const parsedInput = parseInt(input)
39+
const parsedInput = parseInt(input);
4040
if ( parsedInput < 0 ) {
41-
console.log(usage)
41+
console.log(usage);
4242
}
4343
else if ( parsedInput > 170 ) {
44-
console.log(`Input of ${parsedInput} is too large to calculate a factorial for. Max input is 170.`)
44+
console.log(`Input of ${parsedInput} is too large to calculate a factorial for. Max input is 170.`);
4545
}
4646
else {
47-
console.log(factorial(parsedInput))
47+
console.log(factorial(parsedInput));
4848
}
4949
}
5050
else {
5151
// Anything non integer
52-
console.log(usage)
52+
console.log(usage);
5353
}
5454

5555
}
5656

5757
// Run the executable function
58-
const input = process.argv[2]
59-
main(input)
58+
const input = process.argv[2];
59+
main(input);

archive/j/javascript/fibonacci.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ num = process.argv[2];
1616
if (num && !isNaN(num)) {
1717
fibonacci(num);
1818
} else {
19-
console.log("Usage: please input the count of fibonacci numbers to output")
19+
console.log("Usage: please input the count of fibonacci numbers to output");
2020
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
console.log("Hello, World!")
1+
console.log("Hello, World!");

archive/j/javascript/insertion-sort.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ sanitizeArray = (list) => {
2828
const main = (input) => {
2929
try {
3030
arr = sanitizeArray(input);
31-
arr.length <= 1 ? exit() : console.log(insertionSort(arr));
31+
arr.length <= 1 ? exit() : console.log(insertionSort(arr).join(", "));
3232
} catch(err) {
3333
exit();
3434
}

archive/j/javascript/job-sequencing.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,4 @@ const main = (string1, string2) => {
9797
}
9898
}
9999

100-
main(process.argv[2], process.argv[3])
100+
main(process.argv[2], process.argv[3]);

archive/j/javascript/linear-search.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
function LinSearch(arr = [], valToSearch) {
22
let check = false;
3-
if (arr.length == 0) return check
4-
if(valToSearch==='') return check
3+
if (arr.length == 0) return check;
4+
if(valToSearch==='') return check;
55
else {
66
for (i = 0; i < arr.length; i++) {
77
if (arr[i] == valToSearch){
8-
check = true
9-
return check
8+
check = true;
9+
return check;
1010
}
1111
}
12-
return check
12+
return check;
1313
}
1414
}
1515

@@ -23,7 +23,7 @@ sanitizeArray = (list) => {
2323

2424
const exit = () => {
2525
const usage = 'Usage: please provide a list of integers ("1, 4, 5, 11, 12") and the integer to find ("11")';
26-
console.log(usage)
26+
console.log(usage);
2727
process.exit();
2828
}
2929

@@ -36,4 +36,4 @@ const main = (input, key) => {
3636
}
3737
}
3838

39-
main(process.argv[2], process.argv[3])
39+
main(process.argv[2], process.argv[3]);

archive/j/javascript/merge-sort.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const main = (input) => {
3737
});
3838
arr = arr.filter(n => n);
3939
arr=mergeSort(arr);
40-
console.log(arr);
40+
console.log(arr.join(", "));
4141
}
4242
else {
4343
console.log(usage);
@@ -52,4 +52,4 @@ if (process.argv.length > 2) {
5252
}
5353
else {
5454
console.log(usage);
55-
}
55+
}

archive/j/javascript/prime-number.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const isPrime = (number) => {
22
if(number <= 1)
3-
return false
3+
return false;
44

55
for (let i = 2; i <= Math.sqrt(number); i++) {
66
if (number % i == 0) {
@@ -11,7 +11,7 @@ const isPrime = (number) => {
1111
};
1212

1313
const input = process.argv[2];
14-
let number = Number(input)
14+
let number = Number(input);
1515

1616
if (input !== '' && Number.isInteger(number) && number >= 0) {
1717
isPrime(input) ? console.log("prime") : console.log("composite");

0 commit comments

Comments
 (0)