Errata

Data Structures and Algorithms with JavaScript

Errata for Data Structures and Algorithms with JavaScript

Submit your own errata for this product.

The errata list is a list of errors and their corrections that were found after the product was released. If the error was corrected in a later version or reprint the date of the correction will be displayed in the column titled "Date Corrected".

The following errata were submitted by our customers and approved as valid errors by the author or editor.

Color key: Serious technical mistake Minor technical mistake Language or formatting error Typo Question Note Update

Version Location Description Submitted By Date submitted Date corrected
Printed, PDF, ePub, Mobi,
Page -
Kindle Edition - Section on List Iterators

The iterators for Lists as written in Ch 3 result in an infinite loop - as a result of how prev() and next() are written.

Note: I am running the examples using the Node.js shell.

Note from the Author or Editor:
*Examples have been modified directly in text*

Reviewer is correct, and code has been corrected.

Brian Scaturro  Mar 27, 2014  Jul 25, 2014
Other Digital Version
online examples
example content

The BFS function is never called in any of these programs - even inside the book.

Note from the Author or Editor:
* Text corrected in copy *

The bfs function is called in some of the applications, but wasn't called in the others. The text has been corrected. The examples have also been corrected and will be rolled out in a couple of weeks.

Anonymous  Apr 28, 2014  Jul 25, 2014
PDF, ePub
Page 3
1st heading

Typo in initializing: Declaring and Intializing Variables

Note from the Author or Editor:
*Corrected in text*

Should be Initializing

Alfredo Delgado  Apr 26, 2014  Jul 25, 2014
PDF
Page 20
Unshift code example

The example in the book incorrectly displays the output of the result from the second unshift operation. The example shows:

var nums = [2,3,4,5];
print(nums); // 2,3,4,5
var newnum = 1;
nums.unshift(newnum);
print(nums); // 1,2,3,4,5
nums = [3,4,5];
nums.unshift(newnum,1,2);
print(nums); // 1,2,3,4,5

In the last line of the example print(nums) will output 1,1,2,3,4,5 because nums.unshift(newnum,1,2) is adding 1,1,2 to the nums array.

Note from the Author or Editor:
* corrected in text *

Last unshift should be

nums.unshift(newnum, 2);

Omer Wazir  Mar 18, 2014  Jul 25, 2014
PDF
Page 21
Adding and Removing Elements from the Middle of an Array (the simple example)

This is the current example in the PDF:

var nums = [1,2,3,7,8,9];
var newElements = [4,5,6];
nums.splice(3,0,newElements);
print(nums); // 1,2,3,4,5,6,7,8,9

When adding an array of data using splice(), it will be added as an array, so the results would is going to be:

print(nums); // [1, 2, 3, [4, 5, 6], 7, 8, 9]

Note from the Author or Editor:
*Errata has been confirmed, and fix has been incorporated into text"

Should be:

nums.splice(3,0,4,5,6);

Claude Gauthier  Mar 13, 2014  Jul 25, 2014
PDF, ePub
Page 21
1st sentence under "Adding and Removing Elements from the Middle of an Array"

Currently reads: Trying to add or remove elements *at the end* of an array leads to the same problems we find when trying to add or remove elements from the beginning of an array?both operations require shifting array elements either toward the beginning or toward the end of the array.

Probably meant: Trying to add or remove elements *from the middle* of an array leads to the same problems we find when trying to add or remove elements from the beginning of an array?both operations require shifting array elements either toward the beginning or toward the end of the array.

Note from the Author or Editor:
* corrected directly in text*

Yes, it should be "in the middle" not "at the end"

Alfredo Delgado  Apr 29, 2014  Jul 25, 2014
PDF
Page 22
2nd paragraph

The PDF shows:

var names = ["David","Mike","Cynthia","Clayton","Bryan","Raymond"];
nums.sort();
print(nums); // Bryan,Clayton,Cynthia,David,Mike,Raymond

But I think the author really intended to write:

var names = ["David","Mike","Cynthia","Clayton","Bryan","Raymond"];
names.sort();
print(names); // Bryan,Clayton,Cynthia,David,Mike,Raymond

Note from the Author or Editor:
* corrected in text *

Chris  Apr 25, 2014  Jul 25, 2014
PDF
Page 39
Insert: Inserting an Element into a List, last paragraph

"Once this position is found, we use shift() to insert the new element into the list."

Should be:

"Once this position is found, we use splice() to insert the new element into the list."

Note from the Author or Editor:
*edited in text*

Submitter is correct, and typo has been fixed

H?liton Nordt  Mar 11, 2014  Jul 25, 2014
PDF
Page 39
Code example for removing elements from a list object

The code example for Clear: Removing All Elements from a List shows:
function clear() {
delete this.dataStore;
this.dataStore = [];
this.listSize = this.pos = 0;
}

The problem is that this.dataStore = [] is not the correct way to clear an array. It should be this.dataStore.length = 0

Any reference to the List or to the datastore will contain the old values if this.dataSTore = [] is used.

Note from the Author or Editor:
*This item has been fixed in the text*

Reviewer is correct, it should have been this.dataStore.length = 0;

Omer Wazir  Mar 24, 2014  Jul 25, 2014
Other Digital Version
71
first code sample

function dequeue() {
var priority = this.dataStore[0].code;
for (var i = 1; i < this.dataStore.length; ++i) {
if (this.dataStore[i].code < priority) {
priority = i;
}
}
return this.dataStore.splice(priority,1);
}

and the accompanying output does not actually return the lowest code patient in the queue as the text suggests it should. You will see in the output that Jones, with code 4 is treated first, when it is Brown with code 1 that should be first.

The dequeue function, in order to work as suggested should read as follows:

function dequeue() {
var priority = 0
for (var i = 1; i < this.dataStore.length; i+=1) {
if (this.dataStore[i].code < this.dataStore[priority].code) {
priority = i;
}
}
return this.dataStore.splice(priority,1);
}

Note from the Author or Editor:
* Corrected in text*

The dequeue function has been redefined to:

function dequeue() {
var entry = 0;
for (var i = 0; i < this.dataStore.length; ++i) {
if (this.dataStore[i].code < this.dataStore[entry].code) {
entry = i;
}
}
return this.dataStore.splice(entry,1);
}

Matching errata's submitter design, with minor name change

Brett Taylor  Apr 16, 2014  Jul 25, 2014
Printed
Page 89
3rd paragraph

The use of an array in this manner is a serious misunderstanding of JavaScript's way of implementing arrays.

The example states that "JavaScript can't sort the property [keys] of an Object", yet later in the chapter it is stated that string keys don't work and that Object.keys() has to be used.

what this:

this.datastore[key] = value;

does, is that it defines a new property on the object this.datastore, (and for that matter even works if this.datastore is of type Number or String). There is no and has never been any support in arrays for string keys, and saying so is teaching your readers wrongly.

That has nothing to do with sorting or searching, it just conveys the wrong idea.

Also see

http://stackoverflow.com/questions/9526860/why-does-a-string-index-in-a-javascript-array-not-increase-the-length-size

on an explanation why it's a bad idea to use strings on arrays: because then, there is no reliable "length" property as there are no "string indexes" at all. Just use Objects.

Note from the Author or Editor:
* Clarification made directly into text *

Array access notation is an approach to dealing with key-value pairs in JavaScript. Added clarifying text, and some corrections into the code to ensure reader knows we're dealing with objects, not arrays.

Timo Lindemann  Apr 02, 2014  Jul 25, 2014
ePub, Mobi
Page 89
concat example code snippet

Third line in code example: variables 'cis' and 'dmp', as part of concat method, should be instead 'cisDept' and 'dmpDept' respectively.

Fifth line in code example: variable 'dmp' as part of concat method, should instead be 'dmpDept'.

Note from the Author or Editor:
*errata confirmed - corrected in the text*

Suz Hinton  May 21, 2014  Jul 25, 2014
PDF
Page 133
Figure 10-7

"Figure 10-7. Removing node with two children" but the picture shows nothing to do with removing node. Even it's not BST.

Note from the Author or Editor:
* edited in text*

This was a duplicate of figure 10-2, and has been removed from the text.

Jungeun Woo  May 28, 2014  Jul 25, 2014
ePub
Page 6704
Location 6704 in function bfs

This is the bfs function for the Graph data structure

when checking for the value that was removed from the queue, it is supposed to look for a value of the removed element and then print the visited vertex.

it states:

if (v == undefined) {
print("Visited vertex: " + v);
}

it should be:
if (v != undefined) {
print("Visited vertex: " + v);
}

Note from the Author or Editor:
* corrected in text *

It has been changed to

(if v !== undefined)

Strict equality is necessary with undefined and null

darrell brown  Mar 15, 2014  Jul 25, 2014
ePub
Page 6764

this.edgeTo[w] = v isn't previously defined.

tried to run the function (bfs). It doesn't produce any results regarding the vertices visited.

Note from the Author or Editor:
* text corrected in copy *

The edgeTo function is used in examples later in chapter, and was included in Graph accidentally at this point.

Text has been corrected, and corrected examples will be rolled out in a couple of weeks

darrell brown  Mar 15, 2014  Jul 25, 2014