data_structures_and_algorithms_using_javascript's Issues
Chapter 12: no CArray.js file
Either make a copy of Chap12-1.js and rename it to CArray.js or make a symbolic link. Or else codes won't run,
$ grep 'load("CArray.js")' *
Chap12-10.js:load("CArray.js")
Chap12-11.js:load("CArray.js")
Chap12-12.js:load("CArray.js");
duplicate folders in Chapter10
In Chapter10 folder,, there is a Chapter9 folder and it contains a Chapter8 folder.
chap6-4txt
function insert(newElement, item) {
var newNode = new Node(newElement);
var current = this.find(item);
newNode.next = current.next;
newNode.previous = current;
current.next = newNode;
}```
should maintain the previous pointer of current.next,right?
text notes shift() instead of splice() used in the code
On page 39 of chapter 3, the text below the code for the insert function specifies shift(). It should be corrected to splice() as per the code example.
function insert(element, after) {
var insertPos = this.find(after);
if(insertPos > -1) {
this.dataStore.splice(insertPos+1, 0, element);
++this.listSize;
return true;
}
return false;
}
Chapter 4 wrong section
- First: Chapter 4 is a duplicate of another chapter and does not contain the Stack examples, it also contains a duplicate directory of Chapter-1.
- Second: The book uses some old coding practices that might not be noticed by beginners. For example we can now confidently use native functions for things like the Stack. Here is a performance analysis over different Array.push() functions, and take notice that Node.js uses the same V8 engine as Chrome.
Zip file?
Not sure if it was intentional or not, but this repo contains the zip of the source code. Wouldn't it be better to have just the code unzipped with folders directly in the repo? I'm sure others, like myself, would like to browse the code directly on github while reading the book rather than have to download it.
Thanks.
Chapter 11: no Graph.js file
codes can't run
chaper11-3:load("Graph.js")
what is the path.push(s)?
function pathTo(v) { var source=0; if(!this.hasPathTo(v)){ return undefined; } var path=[]; for(var i=v; i !=source; i=this.edgeTo[i]) { path.push[i]; } path.push(s); return path; }
Chap14-2.js : 'haven' and 'havoc' wrong answer
for the first char in a string , it could be equal.
function longestSubString(a, b) {
var arr = [];
for (var i = 0; i < a.length; i++) {
arr[i] = [];
for (var j = 0; j < b.length; j++) {
arr[i][j] = 0;
}
}
var max = 0;
var index = 0;
for (var i = 0; i < a.length; i++) {
for (var j = 0; j < b.length; j++) {
//for boundary element
if (i === 0 || j === 0) {
if (a[i] === b[j]) {
arr[i][j] = 1;
max = 1;
} else {
arr[i][j] = 0;
}
} else {
if (a[i] === b[j]) {
arr[i][j] = arr[i - 1][j - 1] + 1;
} else {
arr[i][j] = 0;
}
}
if (max < arr[i][j]) {
max = arr[i][j];
index = i;
}
}
}
var str = "";
if (max == 0) {
return "";
}
else {
for (var i = index+1 - max; i <= index; ++i) {
str += a[i];
}
return str;
}
}
Ask for help
Where is the reference answer code of the exercise
Code for BFS on page 150 does not work and is never called
The BFS function is never called in any of these programs - even inside the book.
an endless loop in chapter 3
we use these code to traverse the names List in chapter, but, the property 'pos' will alaways less than 'listSize', so there will be a endless loop..
for(names.front(); names.currPos() < names.length(); names.next()) {
print(names. getElement());
}
Chap14-2.js line 36 , "word2" should be "word1"。
In the 36 line word2 should be word1。
str += word1[i];
Is there any codes for every chapter exercises?
insertionSort(): var outer initialized as 1 or 0?
I think I found a duplicate prediction in the code.
Code example in the book, Chapter 12.
function insertionSort() {
var temp, inner;
for (var outer = 1; outer <= this.dataStore.length-1; ++outer) {
temp = this.dataStore[outer];
inner = outer;
while (inner > 0 && (this.dataStore[inner-1] >= temp)) {
this.dataStore[inner] = this.dataStore[inner-1];
--inner;
}
this.dataStore[inner] = temp;
}
}
The var outer initialized as 1. Let's change it to 0. It doesn't affect the function.
Because the inner > 0 in while loop guards against out of bound error in this.dataStore(inner - 1).
Therefore, either we initialize outer with 0 or initialize outer with 1 but drop inner > 0 predict since we don't need it.
I prefer setting outer to 0 at the beginning.
function insertionSort() {
var temp, inner;
for (var outer = 0; outer <= this.dataStore.length-1; ++outer) {
temp = this.dataStore[outer];
inner = outer;
while (inner > 0 && (this.dataStore[inner-1] >= temp)) {
this.dataStore[inner] = this.dataStore[inner-1];
--inner;
}
this.dataStore[inner] = temp;
}
}
chapter3 duplicated `length` method and not have `contains` method.
What is push(s);
function pathTo(v) {
var source = 0;
if (!this.hasPathTo(v)) {
return undefined;
}
var path = [];
for (var i = v; i != source; i = this.edgeTo[i]) {
path.push(i);
}
path.push(s);
return path;
}
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.