From 5d9f8c68dca6c43f4c6a25fc769c7e6af15c4511 Mon Sep 17 00:00:00 2001 From: Loiane Groner Date: Wed, 1 Jun 2016 00:02:58 -0300 Subject: [PATCH 01/12] reviewed code bundle --- chapter04/03-PriorityQueue.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/chapter04/03-PriorityQueue.js b/chapter04/03-PriorityQueue.js index f9071ddc..3b029e4d 100644 --- a/chapter04/03-PriorityQueue.js +++ b/chapter04/03-PriorityQueue.js @@ -50,7 +50,5 @@ let priorityQueue = new PriorityQueue(); priorityQueue.enqueue("John", 2); priorityQueue.enqueue("Jack", 1); priorityQueue.enqueue("Camila", 1); -priorityQueue.enqueue("Maxwell", 2); -priorityQueue.enqueue("Ana", 3); priorityQueue.print(); From b6f84d04665e6f98aed8f1089f3ee6e784aed9b1 Mon Sep 17 00:00:00 2001 From: Loiane Groner Date: Fri, 10 Jun 2016 15:39:43 -0300 Subject: [PATCH 02/12] Update 14-ES6ParameterHandling.js --- chapter01/14-ES6ParameterHandling.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/chapter01/14-ES6ParameterHandling.js b/chapter01/14-ES6ParameterHandling.js index 706c2059..4645f2a7 100644 --- a/chapter01/14-ES6ParameterHandling.js +++ b/chapter01/14-ES6ParameterHandling.js @@ -30,8 +30,8 @@ function restParamaterFunction (x, y, ...a) { console.log(restParamaterFunction(1, 2, "hello", true, 7)); // outputs 9; //code above is the same as ES5: -function restParamaterFunction (x, y) { +function restParamaterFunction2 (x, y) { var a = Array.prototype.slice.call(arguments, 2); return (x + y) * a.length; }; -console.log(restParamaterFunction2(1, 2, "hello", true, 7)); \ No newline at end of file +console.log(restParamaterFunction2(1, 2, "hello", true, 7)); From 2cb57e826889e02d2bd6578255997fa3e75dd8e1 Mon Sep 17 00:00:00 2001 From: Loiane Groner Date: Fri, 10 Jun 2016 15:46:08 -0300 Subject: [PATCH 03/12] Update 02-UsingDictionaries.js --- chapter07/02-UsingDictionaries.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/chapter07/02-UsingDictionaries.js b/chapter07/02-UsingDictionaries.js index 3ec30d4b..dc0bf258 100644 --- a/chapter07/02-UsingDictionaries.js +++ b/chapter07/02-UsingDictionaries.js @@ -11,9 +11,9 @@ console.log(dictionary.keys()); //outputs ["Gandalf", "John", "Tyrion"] console.log(dictionary.values()); //outputs ["gandalf@email.com", "johnsnow@email.com", "tyrion@email.com"] console.log(dictionary.get('Tyrion')); //outputs tyrion@email.com -dictionary.delete(‘John'); +dictionary.delete('John'); console.log(dictionary.keys()); //outputs ["Gandalf", "Tyrion"] console.log(dictionary.values()); //outputs ["gandalf@email.com", "tyrion@email.com"] -console.log(dictionary.getItems()); //Object {Gandalf: "gandalf@email.com", Tyrion: "tyrion@email.com"} \ No newline at end of file +console.log(dictionary.getItems()); //Object {Gandalf: "gandalf@email.com", Tyrion: "tyrion@email.com"} From d0ebbf9b87573ceb29240e177c7f69448aacc5b8 Mon Sep 17 00:00:00 2001 From: Loiane Groner Date: Thu, 25 Aug 2016 09:18:00 -0300 Subject: [PATCH 04/12] removed print tree function (did not exist) --- chapter08/02-UsingBinarySearchTree.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/chapter08/02-UsingBinarySearchTree.js b/chapter08/02-UsingBinarySearchTree.js index 41f2c691..eb139837 100644 --- a/chapter08/02-UsingBinarySearchTree.js +++ b/chapter08/02-UsingBinarySearchTree.js @@ -50,7 +50,3 @@ tree.inOrderTraverse(printNode); console.log('********* raw data structure ***********'); console.log(tree.getRoot()); - -console.log('********* printing HTML tree ***********'); -var parent = document.getElementsByTagName('body')[0]; -printHTMLTree(tree.getRoot(), parent, 255); \ No newline at end of file From 78685366d9fa14d5e1d8c84e359f1336782a1330 Mon Sep 17 00:00:00 2001 From: Loiane Groner Date: Thu, 1 Sep 2016 14:10:05 -0300 Subject: [PATCH 05/12] closes #13 --- chapter07/07-HashCollisionLinearProbing.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/chapter07/07-HashCollisionLinearProbing.js b/chapter07/07-HashCollisionLinearProbing.js index 74fdbac5..38b07c0f 100644 --- a/chapter07/07-HashCollisionLinearProbing.js +++ b/chapter07/07-HashCollisionLinearProbing.js @@ -46,10 +46,10 @@ function HashLinearProbing(){ return table[position].value; } else { var index = ++position; - while (table[index] === undefined || table[index].key !== key){ + while (table[index] !== undefined && (table[index] && table[index].key !== key)){ index++; } - if (table[index].key === key) { + if (table[index] && table[index].key === key) { return table[index].value; } } @@ -82,4 +82,4 @@ function HashLinearProbing(){ } } }; -} \ No newline at end of file +} From 2a89e21fc883821c6da1068c8d6f4b659f9f7fb3 Mon Sep 17 00:00:00 2001 From: Victor Wang <2501211450@qq.com> Date: Sun, 11 Sep 2016 16:19:51 +0800 Subject: [PATCH 06/12] Update 05-CircularLinkedList2.js fix some errors --- chapter05/05-CircularLinkedList2.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/chapter05/05-CircularLinkedList2.js b/chapter05/05-CircularLinkedList2.js index 13f36665..5aab62d0 100644 --- a/chapter05/05-CircularLinkedList2.js +++ b/chapter05/05-CircularLinkedList2.js @@ -133,8 +133,8 @@ let CircularLinkedList2 = (function () { remove(element) { - let index = indexOf(element); - return removeAt(index); + let index = this.indexOf(element); + return this.removeAt(index); } indexOf(element) { @@ -198,4 +198,4 @@ let CircularLinkedList2 = (function () { } } return CircularLinkedList2; -})(); \ No newline at end of file +})(); From 94b2c6826736363a03443aa905ae051dda030169 Mon Sep 17 00:00:00 2001 From: beizhedenglong <2501211450@qq.com> Date: Sun, 11 Sep 2016 23:26:57 +0800 Subject: [PATCH 07/12] fix bug in CircularLinkedList There is a bug in insert function. If you insert an element in an empty list at the first position. It will throw a TypeError: Cannot read property 'next' of null. --- chapter05/05-CircularLinkedList.js | 27 +++++++++++++++++---------- chapter05/05-CircularLinkedList2.js | 21 ++++++++++++--------- 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/chapter05/05-CircularLinkedList.js b/chapter05/05-CircularLinkedList.js index 5f05e85f..c3151148 100644 --- a/chapter05/05-CircularLinkedList.js +++ b/chapter05/05-CircularLinkedList.js @@ -46,16 +46,22 @@ function CircularLinkedList() { index = 0; if (position === 0){ //add on first position - - node.next = current; - - //update last element - while(current.next !== head){ //last element will be head instead of NULL - current = current.next; + + if(!head){ // if no node in list + head = node; + node.next = head; + }else{ + node.next = current; + + //update last element + while(current.next !== head){ //last element will be head instead of NULL + current = current.next; + } + + head = node; + current.next = head; } - - head = node; - current.next = head; + } else { while (index++ < position){ @@ -180,4 +186,5 @@ function CircularLinkedList() { this.print = function(){ console.log(this.toString()); }; -} \ No newline at end of file +} + diff --git a/chapter05/05-CircularLinkedList2.js b/chapter05/05-CircularLinkedList2.js index 5aab62d0..6f7574ef 100644 --- a/chapter05/05-CircularLinkedList2.js +++ b/chapter05/05-CircularLinkedList2.js @@ -58,15 +58,18 @@ let CircularLinkedList2 = (function () { if (position === 0) { //add on first position - node.next = current; - - //update last element - while (current.next !== this.getHead()) { //last element will be head instead of NULL - current = current.next; - } - - head.set(this, node); - current.next = this.getHead(); + if(!this.getHead()) { // if no node in list + head.set(this, node); + node.next = this.getHead(); + } else { + node.next = current; + //update last element + while(current.next !== this.getHead()) { //last element will be head instead of NULL + current = current.next; + } + head.set(this, node); + current.next = this.getHead(); + } } else { while (index++ < position) { From c2eb4acefba97503766ac59158d299c22a56c5f8 Mon Sep 17 00:00:00 2001 From: TerryX Date: Wed, 2 Nov 2016 23:21:11 +0800 Subject: [PATCH 08/12] Fix aValues being undefined --- chapter02/06-ES6Methods.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chapter02/06-ES6Methods.js b/chapter02/06-ES6Methods.js index 60468aa4..bf4eb36a 100644 --- a/chapter02/06-ES6Methods.js +++ b/chapter02/06-ES6Methods.js @@ -40,7 +40,7 @@ console.log(aKeys.next()); // {value: 1, done: false } console.log(aKeys.next()); // {value: 2, done: false } console.log('Array.values'); -//let aValues = numbers.values(); +let aValues = numbers.values(); console.log(aValues.next()); // {value: 1, done: false } done false means iterator has more values console.log(aValues.next()); // {value: 2, done: false } console.log(aValues.next()); // {value: 3, done: false } From a5fc23e474e68f9edbf003271264e447d65310ac Mon Sep 17 00:00:00 2001 From: Loiane Groner Date: Mon, 17 Apr 2017 14:26:05 -0300 Subject: [PATCH 09/12] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4e9eca37..64771d99 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Source code of **Learning JavaScript Data Structures and Algorithms** book. | 1st edition | 2nd edition | | ------------- |:-------------:| -| ![1st edition](https://d1ldz4te4covpm.cloudfront.net/sites/default/files/imagecache/ppv4_main_book_cover/4874OS_Learning%20JavaScript%20Data%20Structures%20and%20Algorithms.jpg) | ![2nd edition](https://dz13w8afd47il.cloudfront.net/sites/default/files/imagecache/ppv4_main_book_cover/B05348_MockupCover_Normal.jpg) | +| ![1st edition](https://d1ldz4te4covpm.cloudfront.net/sites/default/files/imagecache/ppv4_main_book_cover/4874OS_Learning%20JavaScript%20Data%20Structures%20and%20Algorithms.jpg) | ![2nd edition](https://d255esdrn735hr.cloudfront.net/sites/default/files/imagecache/ppv4_main_book_cover/5493OS_5348_Learning%20JavaScript%20Data%20Structures%20and%20Algorithms,%20Second%20Edition.jpg) | | [Book link](http://amzn.to/1Y1OWPx)| [Book link](http://amzn.to/1TSkcA1)| Book link - first edition: @@ -17,6 +17,7 @@ Book link - first edition: Book link - second edition: - [Packt](https://www.packtpub.com/web-development/learning-javascript-data-structures-and-algorithms-second-edition) - [Amazon](http://amzn.to/1TSkcA1) + - [Brazilian Portuguese version](https://novatec.com.br/livros/estruturas-de-dados-algoritmos-em-javascript/) ### List of Chapters: From c44e74918af79cb45532cc7423bdcb3a853f27fd Mon Sep 17 00:00:00 2001 From: loiane Date: Mon, 21 Aug 2017 09:57:03 -0300 Subject: [PATCH 10/12] fixes #23 --- chapter07/07-HashCollisionLinearProbing.js | 9 +++++++++ chapter07/08-UsingHashCollisionLinearProbing.js | 8 ++++++++ 2 files changed, 17 insertions(+) diff --git a/chapter07/07-HashCollisionLinearProbing.js b/chapter07/07-HashCollisionLinearProbing.js index 38b07c0f..4b1172be 100644 --- a/chapter07/07-HashCollisionLinearProbing.js +++ b/chapter07/07-HashCollisionLinearProbing.js @@ -53,6 +53,15 @@ function HashLinearProbing(){ return table[index].value; } } + } else { //search for possible deleted value + var index = ++position; + while (table[index] == undefined || index == table.length || + (table[index] !== undefined && table[index] && table[index].key !== key)){ + index++; + } + if (table[index] && table[index].key === key) { + return table[index].value; + } } return undefined; }; diff --git a/chapter07/08-UsingHashCollisionLinearProbing.js b/chapter07/08-UsingHashCollisionLinearProbing.js index 902384ee..36a33e61 100644 --- a/chapter07/08-UsingHashCollisionLinearProbing.js +++ b/chapter07/08-UsingHashCollisionLinearProbing.js @@ -26,4 +26,12 @@ console.log('**** Remove **** '); hashLinearProbing.remove('Gandalf'); console.log(hashLinearProbing.get('Gandalf')); +hashLinearProbing.print(); + +console.log('**** Remove Test 2 **** '); +console.log('Removing Jonathan', hashLinearProbing.remove('Jonathan')); +console.log('**** Print **** '); +hashLinearProbing.print(); +console.log('Get Jamie', hashLinearProbing.get('Jamie')); +console.log('**** Print **** '); hashLinearProbing.print(); \ No newline at end of file From 10b24fd4a3ec01aa8db5a5bffb29e55559647dae Mon Sep 17 00:00:00 2001 From: loiane Date: Thu, 7 Sep 2017 09:18:28 -0300 Subject: [PATCH 11/12] gitignore --- .gitignore | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 6fee6d3a..2458e8b0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ .idea/* -*.log \ No newline at end of file +*.log +node_modules +coverage From f06567601501477cb470a8e0b59cfb9f36d8d19d Mon Sep 17 00:00:00 2001 From: Loiane Groner Date: Mon, 20 Nov 2017 13:09:10 -0200 Subject: [PATCH 12/12] Update 14-ES6ParameterHandling.js --- chapter01/14-ES6ParameterHandling.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chapter01/14-ES6ParameterHandling.js b/chapter01/14-ES6ParameterHandling.js index 4645f2a7..af23585c 100644 --- a/chapter01/14-ES6ParameterHandling.js +++ b/chapter01/14-ES6ParameterHandling.js @@ -14,7 +14,7 @@ function sum2 (x, y, z) { z = 3; return x + y + z; }; -console.log(sum2(4,2)); //outpus 10 +console.log(sum2(4,2)); //outpus 9 //******* EcmaScript 6: spread operator ('...') var params = [3, 4, 5];