Skip to content

Commit c19197b

Browse files
committed
Merge branch 'master' of https://github.com/loiane/javascript-datastructures-algorithms into third-edition
2 parents e54c64a + 19b2cab commit c19197b

10 files changed

+15232
-36
lines changed

package-lock.json

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

package.json

+8-4
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
"generate-report": "nyc --report-dir coverage npm run test && nyc report --reporter=text",
3131
"generate-report2": "nyc --report-dir coverage npm run test",
3232
"go": "npm run clean && npm run lint && npm run build && npm run test",
33-
"webpack": "webpack --env build"
33+
"webpack": "webpack --env build",
34+
"serve" :"http-server"
3435
},
3536
"nyc": {
3637
"include": [
@@ -54,7 +55,7 @@
5455
},
5556
"devDependencies": {
5657
"@types/chai": "^4.1.2",
57-
"@types/mocha": "^5.0.0",
58+
"@types/mocha": "^5.2.0",
5859
"babel-cli": "^6.26.0",
5960
"babel-core": "^6.26.0",
6061
"babel-eslint": "^8.2.2",
@@ -70,12 +71,15 @@
7071
"istanbul": "^v1.1.0-alpha.1",
7172
"mocha": "^5.0.4",
7273
"mochawesome": "^3.0.2",
73-
"nyc": "^11.6.0",
74+
"nyc": "11.7.0",
7475
"ts-node": "^5.0.1",
7576
"tslint": "^5.9.1",
7677
"typescript": "^2.7.2",
7778
"webpack": "^4.1.1",
78-
"webpack-cli": "^2.0.12",
79+
"webpack-cli": "2.0.14",
7980
"yargs": "^11.0.0"
81+
},
82+
"dependencies": {
83+
"http-server": "^0.11.1"
8084
}
8185
}

src/js/algorithms/sorting/quicksort.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,15 @@ function partition(array, left, right, compareFn) {
44
const pivot = array[Math.floor((right + left) / 2)];
55
let i = left;
66
let j = right;
7-
// console.log('pivot is ' + pivot + '; left is ' + left + '; right is ' + right);
7+
88
while (i <= j) {
99
while (compareFn(array[i], pivot) === Compare.LESS_THAN) {
1010
i++;
11-
// console.log('i = ' + i);
1211
}
1312
while (compareFn(array[j], pivot) === Compare.BIGGER_THAN) {
1413
j--;
15-
// console.log('j = ' + j);
1614
}
1715
if (i <= j) {
18-
// console.log('swap ' + array[i] + ' with ' + array[j]);
1916
swap(array, i, j);
2017
i++;
2118
j--;

src/js/others/balanced-symbols.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export function parenthesesChecker(symbols) {
1111
let top;
1212

1313
while (index < symbols.length && balanced) {
14-
symbol = symbols.charAt(index);
14+
symbol = symbols[index];
1515
if (opens.indexOf(symbol) >= 0) {
1616
stack.push(symbol);
1717
} else if (stack.isEmpty()) {
@@ -24,8 +24,5 @@ export function parenthesesChecker(symbols) {
2424
}
2525
index++;
2626
}
27-
if (balanced && stack.isEmpty()) {
28-
return true;
29-
}
30-
return false;
27+
return balanced && stack.isEmpty();
3128
}

src/js/others/fibonacci.js

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ export function fibonacciMemoization(n) {
2626
const memo = [0, 1];
2727
const fibonacciMem = num => {
2828
if (memo[num] != null) { return memo[num]; }
29-
memo[num] = fibonacciMem(num - 1) + fibonacciMem(num - 2);
3029
return (memo[num] = fibonacciMem(num - 1) + fibonacciMem(num - 2));
3130
};
3231
return fibonacciMem(n);

src/js/others/palindrome-checker.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,20 @@ export function palindromeChecker(aString) {
1010
}
1111
const deque = new Deque();
1212
const lowerString = aString.toLocaleLowerCase().split(' ').join('');
13-
let isEqual = true;
1413
let firstChar;
1514
let lastChar;
1615

1716
for (let i = 0; i < lowerString.length; i++) {
1817
deque.addBack(lowerString.charAt(i));
1918
}
2019

21-
while (deque.size() > 1 && isEqual) {
20+
while (deque.size() > 1) {
2221
firstChar = deque.removeFront();
2322
lastChar = deque.removeBack();
2423
if (firstChar !== lastChar) {
25-
isEqual = false;
24+
return false;
2625
}
2726
}
2827

29-
return isEqual;
28+
return true;
3029
}

src/js/util.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export function biggerEquals(a, b, compareFn) {
1818

1919
export function defaultCompare(a, b) {
2020
if (a === b) {
21-
return 0;
21+
return Compare.EQUALS;
2222
}
2323
return a < b ? Compare.LESS_THAN : Compare.BIGGER_THAN;
2424
}

src/ts/others/balanced-symbols.ts

+1-12
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,14 @@ export function parenthesesChecker(symbols: string) {
1313
symbol = symbols[index];
1414
if (opens.indexOf(symbol) >= 0) {
1515
stack.push(symbol);
16-
// console.log(`open symbol - stacking ${symbol}`);
1716
} else {
18-
// console.log(`close symbol ${symbol}`);
1917
if (stack.isEmpty()) {
2018
balanced = false;
21-
// console.log('Stack is empty, no more symbols to pop and compare');
2219
} else {
2320
top = stack.pop();
24-
// if (!matches(top, symbol)){
2521
if (!(opens.indexOf(top) === closers.indexOf(symbol))) {
2622
balanced = false;
27-
/* console.log(
28-
`poping symbol ${top} - is not a match compared to ${symbol}`
29-
); */
30-
} /* else {
31-
console.log(
32-
`poping symbol ${top} - is is a match compared to ${symbol}`
33-
);
34-
} */
23+
}
3524
}
3625
}
3726
index++;

src/ts/others/factorial.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export function factorialIterative(number: number) {
44
}
55
let total = 1;
66
for (let n = number; n > 1; n--) {
7-
total = total * n;
7+
total *= n;
88
}
99
return total;
1010
}

src/ts/others/palindrome-checker.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,19 @@ export function palindromeChecker(aString: string) {
99

1010
const deque = new Deque<string>();
1111
const lowerString = aString.toLocaleLowerCase().split(' ').join('');
12-
let isEqual = true;
1312
let firstChar: string, lastChar: string;
1413

1514
for (let i = 0; i < lowerString.length; i++) {
1615
deque.addBack(lowerString.charAt(i));
1716
}
1817

19-
while (deque.size() > 1 && isEqual) {
18+
while (deque.size() > 1) {
2019
firstChar = deque.removeFront();
2120
lastChar = deque.removeBack();
2221
if (firstChar !== lastChar) {
23-
isEqual = false;
22+
return false;
2423
}
2524
}
2625

27-
return isEqual;
26+
return true;
2827
}

0 commit comments

Comments
 (0)