diff --git a/.babelrc b/.babelrc
new file mode 100644
index 00000000..df4ad4d9
--- /dev/null
+++ b/.babelrc
@@ -0,0 +1,7 @@
+{
+ "presets": ["env"],
+ "plugins": [
+ "add-module-exports",
+ "transform-es2015-modules-umd"
+ ]
+}
diff --git a/.bithoundrc b/.bithoundrc
new file mode 100644
index 00000000..46722b1d
--- /dev/null
+++ b/.bithoundrc
@@ -0,0 +1,19 @@
+{
+ "ignore": [
+ "**/.vscode/**",
+ "**/node_modules/**",
+ "**/dist/**",
+ "**/examples/**"
+ ],
+ "test": [
+ "**/test/**"
+ ],
+ "critics": {
+ "lint": {
+ "engine": "eslint"
+ },
+ "wc": {
+ "limit": 1000
+ }
+ }
+}
diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 00000000..8b1709b6
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,12 @@
+root = true
+
+[*]
+indent_style = space
+indent_size = 2
+end_of_line = LF
+charset = utf-8
+trim_trailing_whitespace = true
+insert_final_newline = true
+
+[*.md]
+trim_trailing_whitespace = false
\ No newline at end of file
diff --git a/.eslintrc.json b/.eslintrc.json
new file mode 100644
index 00000000..af313c2f
--- /dev/null
+++ b/.eslintrc.json
@@ -0,0 +1,34 @@
+{
+ "env": {
+ "browser": true,
+ "commonjs": true,
+ "es6": true,
+ "node": true
+ },
+ "globals": {
+ "expect": true,
+ "it": true,
+ "describe": true,
+ "beforeEach": true,
+ "afterEach": true,
+ "document": false,
+ "navigator": false,
+ "window": false
+ },
+ "parser": "babel-eslint",
+ "extends": "airbnb-base",
+ "rules": {
+ "class-methods-use-this": 0,
+ "no-plusplus": 0,
+ "arrow-parens": 0,
+ "no-console": 0,
+ "import/prefer-default-export": 0,
+ "comma-dangle": 0,
+ "no-underscore-dangle": 0,
+ "no-param-reassign": 0,
+ "no-return-assign": 0,
+ "no-restricted-globals": 0,
+ "no-multi-assign": 0,
+ "prefer-destructuring": ["error", {"object": true, "array": false}]
+ }
+}
diff --git a/.firebaserc b/.firebaserc
new file mode 100644
index 00000000..d33152ab
--- /dev/null
+++ b/.firebaserc
@@ -0,0 +1,5 @@
+{
+ "projects": {
+ "default": "javascript-ds-algorithms-book"
+ }
+}
diff --git a/.gitignore b/.gitignore
index 2458e8b0..25cf67d5 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,3 +2,9 @@
*.log
node_modules
coverage
+.nyc_output
+coverage.lcov
+mochawesome-report/*
+dist/js/*
+dist/ts/*
+snippet.js
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 00000000..65552b8d
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,16 @@
+language: node_js
+node_js:
+ - node
+before_script:
+ - npm install -g --silent firebase-tools
+install:
+ - npm install
+script:
+ - npm run go
+after_success:
+ - npm run coverage
+ - test $TRAVIS_BRANCH = "third-edition" && firebase deploy --token $FIREBASE_TOKEN --non-interactive
+notifications:
+ email:
+ on_failure: change
+ on_success: change
diff --git a/.vscode/launch.json b/.vscode/launch.json
new file mode 100644
index 00000000..8b53d61d
--- /dev/null
+++ b/.vscode/launch.json
@@ -0,0 +1,50 @@
+{
+ // Use IntelliSense to learn about possible attributes.
+ // Hover to view descriptions of existing attributes.
+ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
+ "version": "0.2.0",
+ "configurations": [
+ {
+ "type": "chrome",
+ "request": "launch",
+ "name": "Chrome",
+ "url": "http://127.0.0.1:8887/examples",
+ "webRoot": "${workspaceRoot}"
+ },
+ {
+ "type": "node",
+ "request": "launch",
+ "name": "Mocha JS",
+ "program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
+ "args": [
+ "-u",
+ "tdd",
+ "--timeout",
+ "999999",
+ "--compilers",
+ "js:babel-core/register",
+ "--colors",
+ "${workspaceRoot}/test/js/**/*.spec.js"
+ ],
+ "internalConsoleOptions": "openOnSessionStart"
+ },
+ {
+ "type": "node",
+ "request": "launch",
+ "name": "Mocha TS",
+ "program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
+ "args": [
+ "-u",
+ "tdd",
+ "--timeout",
+ "999999",
+ "-r",
+ "ts-node/register",
+ "--colors",
+ "${workspaceRoot}/test/ts/**/**/*.spec.ts"
+ ],
+ "protocol": "auto",
+ "internalConsoleOptions": "openOnSessionStart"
+ }
+ ]
+}
diff --git a/.vscode/settings.json b/.vscode/settings.json
new file mode 100644
index 00000000..55712c19
--- /dev/null
+++ b/.vscode/settings.json
@@ -0,0 +1,3 @@
+{
+ "typescript.tsdk": "node_modules/typescript/lib"
+}
\ No newline at end of file
diff --git a/.vscode/tasks.json b/.vscode/tasks.json
new file mode 100644
index 00000000..9b4e4d2c
--- /dev/null
+++ b/.vscode/tasks.json
@@ -0,0 +1,23 @@
+{
+ // See https://go.microsoft.com/fwlink/?LinkId=733558
+ // for the documentation about the tasks.json format
+ "version": "2.0.0",
+ "tasks": [
+ {
+ "type": "npm",
+ "script": "go",
+ "group": {
+ "kind": "build",
+ "isDefault": true
+ }
+ },
+ {
+ "type": "npm",
+ "script": "dev",
+ "group": {
+ "kind": "test",
+ "isDefault": true
+ }
+ }
+ ]
+}
diff --git a/CHANGELOG.md b/CHANGELOG.md
new file mode 100644
index 00000000..ade741a9
--- /dev/null
+++ b/CHANGELOG.md
@@ -0,0 +1,7 @@
+# Change Log
+All notable changes to the "javascript-datastructures-algorithms" third edition source code bundle will be documented in this file.
+
+Based on [Keep a Changelog](http://keepachangelog.com/).
+
+## [Unreleased]
+- Initial release
diff --git a/README.md b/README.md
index 64771d99..00ae7465 100644
--- a/README.md
+++ b/README.md
@@ -1,12 +1,87 @@
Learning JavaScript Data Structures and Algorithms
====================================
-Source code of **Learning JavaScript Data Structures and Algorithms** book.
+[](https://travis-ci.org/loiane/javascript-datastructures-algorithms)
+[](https://codecov.io/gh/loiane/javascript-datastructures-algorithms)
-| 1st edition | 2nd edition |
-| ------------- |:-------------:|
-|  |  |
-| [Book link](http://amzn.to/1Y1OWPx)| [Book link](http://amzn.to/1TSkcA1)|
+Source code of **Learning JavaScript Data Structures and Algorithms** book, third edition.
+
+Work in Progress.
+
+## List of available chapters:
+
+* 01: [JavaScript, ECMAScript and TypeScript: a quick overview](https://github.com/loiane/javascript-datastructures-algorithms/tree/third-edition/examples/chapter01)
+* 02: [Arrays](https://github.com/loiane/javascript-datastructures-algorithms/tree/third-edition/examples/chapter02)
+* 03: [Stacks](https://github.com/loiane/javascript-datastructures-algorithms/tree/third-edition/examples/chapter03)
+* 04: [Queues and Deques](https://github.com/loiane/javascript-datastructures-algorithms/tree/third-edition/examples/chapter04)
+* 05: [LinkedLists](https://github.com/loiane/javascript-datastructures-algorithms/tree/third-edition/examples/chapter05)
+* 06: [Sets](https://github.com/loiane/javascript-datastructures-algorithms/tree/third-edition/examples/chapter06)
+* 07: [Dictionaries and Hashes](https://github.com/loiane/javascript-datastructures-algorithms/tree/third-edition/examples/chapter07)
+* 08: [Recursion](https://github.com/loiane/javascript-datastructures-algorithms/tree/third-edition/examples/chapter08)
+* 09: [Trees](https://github.com/loiane/javascript-datastructures-algorithms/tree/third-edition/examples/chapter09)
+* 10: [Heap](https://github.com/loiane/javascript-datastructures-algorithms/tree/third-edition/examples/chapter10)
+* 11: [Graphs](https://github.com/loiane/javascript-datastructures-algorithms/tree/third-edition/examples/chapter11)
+* 12: [Sorting and Searching Algorithms](https://github.com/loiane/javascript-datastructures-algorithms/tree/third-edition/examples/chapter12)
+* 13: [String and Math Algorithms](https://github.com/loiane/javascript-datastructures-algorithms/tree/third-edition/examples/chapter13)
+* 14: [Algorithm Design and Techniques](https://github.com/loiane/javascript-datastructures-algorithms/tree/third-edition/examples/chapter14)
+* 15: [Algorithm Complexity](https://github.com/loiane/javascript-datastructures-algorithms/tree/third-edition/examples/chapter15)
+
+### Third Edition Updates
+
+* Algorithms using ES2015+ (ES6+)
+* New data structures and algorithms
+* All chapters rewritten and reviewed
+* Three (3) new chapters
+* Creation of a Data Structures and Algorithms library that can be used in the browser or with Node.js
+* Algorithms tested with Mocha + Chai (test code available in `test` directory)
+* **TypeScript** version of the source code included (library and tests)
+
+## Project Structure
+
+`src/js/index.js` file contains all the data structures and algorithms listed by chapter.
+
+```
+|_examples (how to use each data structure and algorithm, organized by chapter)
+|_src
+|___js (source code: JavaScript version)
+|_____data-structures
+|_______models (classes used by DS: Node, ValuePair, ...)
+|_____others (other algorithms such as palindome checker, hanoi tower)
+|___ts (source code: TypeScript version)
+|_____data-structures
+|_______models
+|_____others
+|_test (unit tests with Mocha and Chai for src)
+|___js (tests for JavaScript code)
+|___ts (tests for TypeScript code)
+```
+
+## Installing and running the book examples With Node
+
+* Install [Node](https://nodejs.org)
+* Open terminal/cmd and change directoty to this project folder: `cd /Users/.../javascript-datastructures-algorithms` (Linux/Max) or `cd C:/.../javascript-datastructures-algorithms`
+* run `npm install` to install all depencies
+* To see the examples, run `http-server html` or `npm run serve`. Open your browser `http:\\localhost:8080` to see the book examples
+* Or `cd html/chapter01` and run each javascript file with node: `node 02-Variables`
+
+## Running the examples in the browser
+
+* Right click on the html file you would like to see the examples, right click and 'Open with Chrome (or any other browser)'
+
+* Or open the `examples/index.html` file to easily nagivate through all examples:
+
+* Demo: [https://javascript-ds-algorithms-book.firebaseapp.com](https://javascript-ds-algorithms-book.firebaseapp.com)
+
+
+
+Happy Coding!
+
+## Other editions
+
+| 1st edition | 2nd edition | 3rd edition |
+| ------------- |:-------------:|:-------------:|
+|  |  |  |
+| [Book link](http://amzn.to/1Y1OWPx)| [Book link](http://amzn.to/1TSkcA1)| [Book link](http://a.co/cbMlYmJ)|
Book link - first edition:
- [Packt](https://www.packtpub.com/application-development/learning-javascript-data-structures-and-algorithms)
@@ -19,24 +94,9 @@ Book link - second edition:
- [Amazon](http://amzn.to/1TSkcA1)
- [Brazilian Portuguese version](https://novatec.com.br/livros/estruturas-de-dados-algoritmos-em-javascript/)
-### List of Chapters:
-
-* 01: [JavaScript: a quick overview](https://github.com/loiane/javascript-datastructures-algorithms/tree/second-edition/chapter01)
-* 02: [Arrays](https://github.com/loiane/javascript-datastructures-algorithms/tree/second-edition/chapter02)
-* 03: [Stacks](https://github.com/loiane/javascript-datastructures-algorithms/tree/second-edition/chapter03)
-* 04: [Queues](https://github.com/loiane/javascript-datastructures-algorithms/tree/second-edition/chapter04)
-* 05: [Linked Lists](https://github.com/loiane/javascript-datastructures-algorithms/tree/second-edition/chapter05)
-* 06: [Sets](https://github.com/loiane/javascript-datastructures-algorithms/tree/second-edition/chapter06)
-* 07: [Dictionaries and Hashes](https://github.com/loiane/javascript-datastructures-algorithms/tree/second-edition/chapter07)
-* 08: [Trees](https://github.com/loiane/javascript-datastructures-algorithms/tree/second-edition/chapter08)
-* 09: [Graphs](https://github.com/loiane/javascript-datastructures-algorithms/tree/second-edition/chapter09)
-* 10: [Sorting and searching algorithms](https://github.com/loiane/javascript-datastructures-algorithms/tree/second-edition/chapter10)
-* 11: [Pattern of algorithms](https://github.com/loiane/javascript-datastructures-algorithms/tree/second-edition/chapter11)
-* 12: [Algorithm Complexity](https://github.com/loiane/javascript-datastructures-algorithms/tree/second-edition/chapter12)
-
-### First Edition source code:
-
-Please refer to [this link](https://github.com/loiane/javascript-datastructures-algorithms/tree/master)
+ Book link - third edition:
+ - [Packt](https://www.packtpub.com/web-development/learning-javascript-data-structures-and-algorithms-third-edition)
+ - [Amazon](http://a.co/cbMlYmJ)
### Found an issue or have a question?
diff --git a/chapter01/02-Variables.js b/chapter01/02-Variables.js
deleted file mode 100644
index 2920e5be..00000000
--- a/chapter01/02-Variables.js
+++ /dev/null
@@ -1,37 +0,0 @@
-var num = 1; //{1}
-num = 3; //{2}
-
-var price = 1.5; //{3}
-var name = 'Packt'; //{4}
-var trueValue = true; //{5}
-var nullVar = null; //{6}
-var und; //7
-
-console.log("num: "+ num);
-console.log("name: "+ name);
-console.log("trueValue: "+ trueValue);
-console.log("price: "+ price);
-console.log("nullVar: "+ nullVar);
-console.log("und: "+ und);
-
-//******* Variable Scope
-
-var myVariable = 'global';
-myOtherVariable = 'global';
-
-function myFunction(){
- var myVariable = 'local';
- return myVariable;
-}
-
-function myOtherFunction(){
- myOtherVariable = 'local';
- return myOtherVariable;
-}
-
-console.log(myVariable); //{1}
-console.log(myFunction()); //{2}
-
-console.log(myOtherVariable); //{3}
-console.log(myOtherFunction()); //{4}
-console.log(myOtherVariable); //{5}
\ No newline at end of file
diff --git a/chapter01/10-ObjectOrientedJS.js b/chapter01/10-ObjectOrientedJS.js
deleted file mode 100644
index c67a6c78..00000000
--- a/chapter01/10-ObjectOrientedJS.js
+++ /dev/null
@@ -1,42 +0,0 @@
-/* Object example 1 */
-
-var obj = new Object();
-
-/* Object example 2 */
-
-var obj = {};
-
-obj = {
- name: {
- first: 'Gandalf',
- last: 'the Grey'
- },
- address: 'Middle Earth'
-};
-
-/* Object example 3 */
-
-function Book(title, pages, isbn){
- this.title = title;
- this.pages = pages;
- this.isbn = isbn;
- this.printIsbn = function(){
- console.log(this.isbn);
- }
-}
-
-var book = new Book('title', 'pag', 'isbn');
-
-console.log(book.title); //outputs the book title
-
-book.title = 'new title'; //update the value of the book title
-
-console.log(book.title); //outputs the updated value
-
-Book.prototype.printTitle = function(){
- console.log(this.title);
-};
-
-book.printTitle();
-
-book.printIsbn();
\ No newline at end of file
diff --git a/chapter01/11-ES6letconst.js b/chapter01/11-ES6letconst.js
deleted file mode 100644
index 6be49b70..00000000
--- a/chapter01/11-ES6letconst.js
+++ /dev/null
@@ -1,47 +0,0 @@
-//******* EcmaScript 6: let and const keywords
-// EcmaScript 6 Constants
-const PI = 3.141593;
-//PI = 3.0; //throws error
-console.log(PI);
-
-//******* EcmaScript 6: let is the new var
-var framework = 'Angular';
-var framework = 'React';
-console.log(framework);
-
-let language = 'JavaScript!';
-//let language = 'Ruby!'; //throws error
-console.log(language);
-
-//******* EcmaScript 6: variables scope
-let movie = 'Lord of the Rings';
-//var movie = 'Batman v Superman'; //throws error, variable movie already declared
-
-function starWarsFan(){
- let movie = 'Star Wars';
- return movie;
-}
-
-function marvelFan(){
- movie = 'The Avengers';
- return movie;
-}
-
-function blizzardFan(){
- let isFan = true;
- let phrase = 'Warcraft';
- console.log('Before if: ' + phrase);
- if (isFan){
- let phrase = 'initial text';
- phrase = 'For the Horde!';
- console.log('Inside if: ' + phrase);
- }
- phrase = 'For the Alliance!';
- console.log('After if: ' + phrase);
-}
-
-console.log(movie);
-console.log(starWarsFan());
-console.log(marvelFan());
-console.log(movie);
-blizzardFan();
\ No newline at end of file
diff --git a/chapter01/12-Es6StringTemplates.js b/chapter01/12-Es6StringTemplates.js
deleted file mode 100644
index 30dc62c1..00000000
--- a/chapter01/12-Es6StringTemplates.js
+++ /dev/null
@@ -1,7 +0,0 @@
-// Template literals
-var book = {
- name: 'Learning JavaScript DataStructures and Algorithms'
-};
-
-console.log(`You are reading ${book.name}.,
- and this is a new line`);
\ No newline at end of file
diff --git a/chapter01/13-ES6ArrowFunctions.js b/chapter01/13-ES6ArrowFunctions.js
deleted file mode 100644
index 317d576f..00000000
--- a/chapter01/13-ES6ArrowFunctions.js
+++ /dev/null
@@ -1,10 +0,0 @@
-//ES6: arrow functions
-let circleArea = (r) => {
- const PI = 3.14;
- let area = PI * r * r;
- return area;
-}
-console.log(circleArea(2));
-
-let circleArea2 = (r) => 3.14 * r * r;
-console.log(circleArea2(2));
\ No newline at end of file
diff --git a/chapter01/15-ES6EnhancedObjectProperties.js b/chapter01/15-ES6EnhancedObjectProperties.js
deleted file mode 100644
index 5f1dd9f1..00000000
--- a/chapter01/15-ES6EnhancedObjectProperties.js
+++ /dev/null
@@ -1,34 +0,0 @@
-// Destructuring Assignment + Property Shorthand
-var [x, y] = ['a', 'b'];
-var obj = { x, y };
-console.log(obj); // { x: "a", y: "b" }
-
-[x, y] = [y, x];
-var temp = x;
-x = y;
-y = temp;
-
-//code above is the same as
-var x = 'a';
-var y = 'b';
-var obj2 = { x: x, y: y };
-console.log(obj2); // { x: "a", y: "b" }
-
-
-// Method Properties
-var hello = {
- name : 'abcdef',
- printHello(){
- console.log('Hello');
- }
-}
-console.log(hello.printHello());
-
-//code above is the same as:
-var hello2 = {
- name: 'abcdef',
- printHello: function printHello() {
- console.log('Hello');
- }
-};
-console.log(hello2.printHello());
\ No newline at end of file
diff --git a/chapter01/16-ES6Classes.js b/chapter01/16-ES6Classes.js
deleted file mode 100644
index 2ec073d9..00000000
--- a/chapter01/16-ES6Classes.js
+++ /dev/null
@@ -1,88 +0,0 @@
-// ES6 classes
-class Book {
- constructor (title, pages, isbn) {
- this.title = title;
- this.pages = pages;
- this.isbn = isbn;
- }
- printIsbn(){
- console.log(this.isbn);
- }
-}
-
-let book = new Book('title', 'pag', 'isbn');
-
-console.log(book.title); //outputs the book title
-
-book.title = 'new title'; //update the value of the book title
-
-console.log(book.title); //outputs the book title
-
-
-//inheritance
-class ITBook extends Book {
-
- constructor (title, pages, isbn, technology) {
- super(title, pages, isbn);
- this.technology = technology;
- }
-
- printTechnology(){
- console.log(this.technology);
- }
-}
-
-let jsBook = new ITBook('Learning JS Algorithms', '200', '1234567890', 'JavaScript');
-
-console.log(jsBook.title);
-console.log(jsBook.printTechnology());
-
-//getter and setters
-class Person {
-
- constructor (name) {
- this._name = name;
- }
-
- get name() {
- return this._name;
- }
-
- set name(value) {
- this._name = value;
- }
-}
-
-let lotrChar = new Person('Frodo');
-console.log(lotrChar.name);
-lotrChar.name = 'Gandalf';
-console.log(lotrChar.name);
-
-lotrChar._name = 'Sam';
-console.log(lotrChar.name);
-
-
-//using symbols for private atributes
-
-var _name = Symbol();
-class Person2 {
-
- constructor (name) {
- this[_name] = name;
- }
-
- get name() {
- return this[_name];
- }
-
- set name(value) {
- this[_name] = value;
- }
-}
-
-let lotrChar2 = new Person2('Frodo');
-console.log(lotrChar2.name);
-lotrChar2.name = 'Gandalf';
-console.log(lotrChar2.name);
-
-console.log(Object.getOwnPropertySymbols(lotrChar2));
\ No newline at end of file
diff --git a/chapter02/06-ES6Methods.js b/chapter02/06-ES6Methods.js
deleted file mode 100644
index bf4eb36a..00000000
--- a/chapter02/06-ES6Methods.js
+++ /dev/null
@@ -1,112 +0,0 @@
-let numbers = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15];
-
-//********** forEch using arrow functions
-console.log('forEach using arrow functions');
-
-numbers.forEach(x => {
- console.log((x % 2 == 0));
-});
-
-//********** using for..of loop
-console.log('using for..of loop');
-
-for (let n of numbers) {
- console.log((n % 2 == 0) ? 'even' : 'odd');
-}
-
-//********** Using the new ES6 iterator (@@iterator)
-console.log('Using the new ES6 iterator (@@iterator)');
-
-let iterator = numbers[Symbol.iterator]();
-console.log(iterator.next().value); //1
-console.log(iterator.next().value); //2
-console.log(iterator.next().value); //3
-console.log(iterator.next().value); //4
-console.log(iterator.next().value); //5
-
-//********** Array entries, keys and values
-console.log('Array entries, keys and values');
-
-console.log('Array.entries');
-let aEntries = numbers.entries(); //retrieve iterator of key/value
-console.log(aEntries.next().value); // [0, 1] - position 0, value 1
-console.log(aEntries.next().value); // [1, 2] - position 1, value 2
-console.log(aEntries.next().value); // [2, 3] - position 2, value 3
-
-console.log('Array.keys');
-let aKeys = numbers.keys(); //retrieve iterator of keys
-console.log(aKeys.next()); // {value: 0, done: false } done false means iterator has more values
-console.log(aKeys.next()); // {value: 1, done: false }
-console.log(aKeys.next()); // {value: 2, done: false }
-
-console.log('Array.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 }
-
-//********** Using the from method
-console.log('Using the from method');
-
-let evens = Array.from(numbers, x => (x % 2 == 0));
-console.log(evens);
-
-let numbers2 = Array.from(numbers);
-console.log(numbers2);
-
-//********** Using Array.of
-console.log('Using Array.of');
-
-let numbers3 = Array.of(1);
-let numbers4 = Array.of(1,2,3,4,5,6);
-let numbersCopy = Array.of(...numbers4);
-console.log(numbers3);
-console.log(numbers4);
-console.log(numbersCopy);
-
-//********** Using the fill method
-console.log('Using the fill method');
-
-numbersCopy.fill(0);
-console.log(numbersCopy);
-
-numbersCopy.fill(2, 1);
-console.log(numbersCopy);
-
-numbersCopy.fill(1, 3, 5);
-console.log(numbersCopy);
-
-let ones = Array(6).fill(1);
-console.log(ones);
-
-//********** Using the copyWithin method
-console.log('Using the copyWithin method');
-
-let copyArray = [1, 2, 3, 4, 5, 6];
-console.log(copyArray);
-
-copyArray = copyArray.copyWithin(0, 3); //pos 3 value is copied to pos 0
-console.log(copyArray);
-
-copyArray = [1, 2, 3, 4, 5, 6];
-copyArray = copyArray.copyWithin(1, 3, 5); //pos 3-4 values are copied to pos 1-2
-console.log(copyArray);
-
-//********** methods find and findIndex
-console.log('methods find and findIndex');
-
-function multipleOf13(element, index, array) {
- return (element % 13 == 0) ? true : false;
-}
-
-console.log(numbers.find(multipleOf13));
-console.log(numbers.findIndex(multipleOf13));
-
-//********** EcmaScript 7: using the method includes
-console.log('EcmaScript 7: using the method includes');
-
-console.log(numbers.includes(15));
-console.log(numbers.includes(20));
-
-let numbers5 = [7,6,5,4,3,2,1];
-console.log(numbers5.includes(4,5));
diff --git a/chapter02/07-TypedArrays.js b/chapter02/07-TypedArrays.js
deleted file mode 100644
index 66a5b29a..00000000
--- a/chapter02/07-TypedArrays.js
+++ /dev/null
@@ -1,26 +0,0 @@
-let length = 5;
-let int16 = new Int16Array(length);
-
-let array16 = [];
-array16.length = length;
-
-for (let i=0; i
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/chapter03/02-UsingStacks.js b/chapter03/02-UsingStacks.js
deleted file mode 100644
index 9876e892..00000000
--- a/chapter03/02-UsingStacks.js
+++ /dev/null
@@ -1,24 +0,0 @@
-let stack = new Stack3();
- console.log(stack.isEmpty()); //outputs true
- stack.push(5);
- stack.push(8);
- console.log(stack.peek()); // outputs 8
- stack.push(11);
- console.log(stack.size()); // outputs 3
- console.log(stack.isEmpty()); //outputs false
- stack.push(15);
- stack.pop();
- stack.pop();
- console.log(stack.size()); // outputs 2
- stack.print(); // outputs [5, 8]
-
-
-//how to ensure true privacy
-//in case using Stack 2 uncomment code below
-/*let objectSymbols = Object.getOwnPropertySymbols(stack);
-
- console.log(objectSymbols.length); // 1
- console.log(objectSymbols); // [Symbol()]
- console.log(objectSymbols[0]); // Symbol()
- stack[objectSymbols[0]].push(1);
- stack.print(); //5, 8, 1*/
\ No newline at end of file
diff --git a/chapter03/03-BalancedSymbols.js b/chapter03/03-BalancedSymbols.js
deleted file mode 100644
index 0d4df4c6..00000000
--- a/chapter03/03-BalancedSymbols.js
+++ /dev/null
@@ -1,41 +0,0 @@
-function parenthesesChecker(symbols){
-
- let stack = new Stack(),
- balanced = true,
- index = 0,
- symbol, top,
- opens = "([{",
- closers = ")]}";
-
- while (index < symbols.length && balanced){
- symbol = symbols.charAt(index);
- if (opens.indexOf(symbol) >= 0){
- stack.push(symbol);
- console.log(`open symbol - stacking ${symbol}`);
- } else {
- console.log(`close symbol ${symbol}`);
- if (stack.isEmpty()){
- balanced = false;
- console.log('Stack is empty, no more symbols to pop and compare');
- } else {
- top = stack.pop();
- //if (!matches(top, symbol)){
- if (!(opens.indexOf(top) === closers.indexOf(symbol))) {
- balanced = false;
- console.log(`poping symbol ${top} - is not a match compared to ${symbol}`);
- } else {
- console.log(`poping symbol ${top} - is is a match compared to ${symbol}`);
- }
- }
- }
- index++;
- }
- if (balanced && stack.isEmpty()){
- return true;
- }
- return false;
-}
-
-console.log(parenthesesChecker('{([])}')); //true
-console.log(parenthesesChecker('{{([][])}()}')); //true
-console.log(parenthesesChecker('[{()]')); //false
\ No newline at end of file
diff --git a/chapter03/05-TowerOfHanoi.js b/chapter03/05-TowerOfHanoi.js
deleted file mode 100644
index ce0fd6dd..00000000
--- a/chapter03/05-TowerOfHanoi.js
+++ /dev/null
@@ -1,26 +0,0 @@
-function towerOfHanoi(n, from, to, helper){
-
- if (n > 0){
- towerOfHanoi(n-1, from, helper, to);
- to.push(from.pop());
- console.log('-----');
- console.log('Source: ' + from.toString());
- console.log('Dest: ' + to.toString());
- console.log('Helper: ' + helper.toString());
- towerOfHanoi(n-1, helper, to, from);
- }
-}
-
-var source = new Stack();
-source.push(3);
-source.push(2);
-source.push(1);
-
-var dest = new Stack();
-var helper = new Stack();
-
-towerOfHanoi(source.size(), source, dest, helper);
-
-source.print();
-helper.print();
-dest.print();
\ No newline at end of file
diff --git a/chapter04/01-Queue.js b/chapter04/01-Queue.js
deleted file mode 100644
index bb22df69..00000000
--- a/chapter04/01-Queue.js
+++ /dev/null
@@ -1,32 +0,0 @@
-function Queue() {
-
- let items = [];
-
- this.enqueue = function(element){
- items.push(element);
- };
-
- this.dequeue = function(){
- return items.shift();
- };
-
- this.front = function(){
- return items[0];
- };
-
- this.isEmpty = function(){
- return items.length == 0;
- };
-
- this.clear = function(){
- items = [];
- };
-
- this.size = function(){
- return items.length;
- };
-
- this.print = function(){
- console.log(items.toString());
- };
-}
diff --git a/chapter04/01-Queue2.js b/chapter04/01-Queue2.js
deleted file mode 100644
index d4bc9891..00000000
--- a/chapter04/01-Queue2.js
+++ /dev/null
@@ -1,49 +0,0 @@
-let Queue2 = (function () {
-
- const items = new WeakMap();
-
- class Queue2 {
-
- constructor () {
- items.set(this, []);
- }
-
- enqueue(element) {
- let q = items.get(this);
- q.push(element);
- }
-
- dequeue() {
- let q = items.get(this);
- let r = q.shift();
- return r;
- }
-
- front() {
- let q = items.get(this);
- return q[0];
- }
-
- isEmpty(){
- return items.get(this).length == 0;
- }
-
- size(){
- let q = items.get(this);
- return q.length;
- }
-
- clear(){
- items.set(this, []);
- }
-
- print(){
- console.log(this.toString());
- }
-
- toString(){
- return items.get(this).toString();
- }
- }
- return Queue2;
-})();
diff --git a/chapter04/02-UsingQueues.html b/chapter04/02-UsingQueues.html
deleted file mode 100644
index 611d3571..00000000
--- a/chapter04/02-UsingQueues.html
+++ /dev/null
@@ -1,12 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/chapter04/02-UsingQueues.js b/chapter04/02-UsingQueues.js
deleted file mode 100644
index 5411bad6..00000000
--- a/chapter04/02-UsingQueues.js
+++ /dev/null
@@ -1,12 +0,0 @@
-let queue = new Queue2();
-console.log(queue.isEmpty()); //outputs true
-queue.enqueue("John");
-queue.enqueue("Jack");
-queue.print();
-queue.enqueue("Camila");
-queue.print();
-console.log(queue.size()); //outputs 3
-console.log(queue.isEmpty()); //outputs false
-queue.dequeue();
-queue.dequeue();
-queue.print();
\ No newline at end of file
diff --git a/chapter04/03-PriorityQueue.js b/chapter04/03-PriorityQueue.js
deleted file mode 100644
index 3b029e4d..00000000
--- a/chapter04/03-PriorityQueue.js
+++ /dev/null
@@ -1,54 +0,0 @@
-function PriorityQueue() {
-
- let items = [];
-
- function QueueElement (element, priority){ // {1}
- this.element = element;
- this.priority = priority;
- }
-
- this.enqueue = function(element, priority){
- let queueElement = new QueueElement(element, priority);
-
- let added = false;
- for (let i=0; i
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/chapter04/03-PriorityQueue2.js b/chapter04/03-PriorityQueue2.js
deleted file mode 100644
index d629334b..00000000
--- a/chapter04/03-PriorityQueue2.js
+++ /dev/null
@@ -1,80 +0,0 @@
-let PriorityQueue2 = (function () {
-
- class QueueElement {
- constructor(element, priority){
- this.element = element;
- this.priority = priority;
- }
- }
-
- const items = new WeakMap();
-
- class PriorityQueue2 { //extends Queue2 { //with this approach the private properties are not reachable through inheritance
-
- constructor () {
- items.set(this, []);
- }
-
- enqueue(element, priority){
- let queueElement = new QueueElement(element, priority);
-
- let q = items.get(this);
-
- let added = false;
- for (let i=0; i 1){
- for (let i=0; i= 0 && position <= length){
-
- let node = new Node(element),
- current = head,
- previous,
- index = 0;
-
- if (position === 0){ //add on first position
-
- node.next = current;
- head = node;
-
- } else {
- while (index++ < position){
- previous = current;
- current = current.next;
- }
- node.next = current;
- previous.next = node;
- }
-
- length++; //update size of list
-
- return true;
-
- } else {
- return false;
- }
- };
-
- this.removeAt = function(position){
-
- //check for out-of-bounds values
- if (position > -1 && position < length){
-
- let current = head,
- previous,
- index = 0;
-
- //removing first item
- if (position === 0){
- head = current.next;
- } else {
-
- while (index++ < position){
-
- previous = current;
- current = current.next;
- }
-
- //link previous with current's next - skip it to remove
- previous.next = current.next;
- }
-
- length--;
-
- return current.element;
-
- } else {
- return null;
- }
- };
-
- this.remove = function(element){
-
- let index = this.indexOf(element);
- return this.removeAt(index);
- };
-
- this.indexOf = function(element){
-
- let current = head,
- index = 0;
-
- while (current) {
- if (element === current.element) {
- return index;
- }
- index++;
- current = current.next;
- }
-
- return -1;
- };
-
- this.isEmpty = function() {
- return length === 0;
- };
-
- this.size = function() {
- return length;
- };
-
- this.getHead = function(){
- return head;
- };
-
- this.toString = function(){
-
- let current = head,
- string = '';
-
- while (current) {
- string += current.element + (current.next ? ', ' : '');
- current = current.next;
- }
- return string;
-
- };
-
- this.print = function(){
- console.log(this.toString());
- };
-}
diff --git a/chapter05/01-LinkedList2.js b/chapter05/01-LinkedList2.js
deleted file mode 100644
index 98452857..00000000
--- a/chapter05/01-LinkedList2.js
+++ /dev/null
@@ -1,170 +0,0 @@
-let LinkedList2 = (function () {
-
- class Node {
- constructor(element){
- this.element = element;
- this.next = null;
- }
- }
-
- const length = new WeakMap();
- const head = new WeakMap();
-
- class LinkedList2 {
-
- constructor () {
- length.set(this, 0);
- head.set(this, null);
- }
-
- append(element) {
-
- let node = new Node(element),
- current;
-
- if (this.getHead() === null) { //first node on list
- head.set(this, node);
- } else {
-
- current = this.getHead();
-
- //loop the list until find last item
- while (current.next) {
- current = current.next;
- }
-
- //get last item and assign next to added item to make the link
- current.next = node;
- }
-
- //update size of list
- let l = this.size();
- l++;
- length.set(this, l);
- }
-
- insert(position, element) {
-
- //check for out-of-bounds values
- if (position >= 0 && position <= this.size()) {
-
- let node = new Node(element),
- current = this.getHead(),
- previous,
- index = 0;
-
- if (position === 0) { //add on first position
-
- node.next = current;
- head.set(this, node);
-
- } else {
- while (index++ < position) {
- previous = current;
- current = current.next;
- }
- node.next = current;
- previous.next = node;
- }
-
- //update size of list
- let l = this.size();
- l++;
- length.set(this, l);
-
- return true;
-
- } else {
- return false;
- }
- }
-
- removeAt(position) {
-
- //check for out-of-bounds values
- if (position > -1 && position < this.size()) {
-
- let current = this.getHead(),
- previous,
- index = 0;
-
- //removing first item
- if (position === 0) {
- head.set(this, current.next);
- } else {
-
- while (index++ < position) {
-
- previous = current;
- current = current.next;
- }
-
- //link previous with current's next - skip it to remove
- previous.next = current.next;
- }
-
- let l = this.size();
- l--;
- length.set(this, l);
-
- return current.element;
-
- } else {
- return null;
- }
- }
-
- remove(element) {
-
- let index = this.indexOf(element);
- return this.removeAt(index);
- }
-
- indexOf(element) {
-
- let current = this.getHead(),
- index = 0;
-
- while (current) {
- if (element === current.element) {
- return index;
- }
- index++;
- current = current.next;
- }
-
- return -1;
- }
-
- isEmpty() {
- return this.size() === 0;
- }
-
- size() {
- return length.get(this);
- }
-
- getHead() {
- return head.get(this);
- }
-
- toString() {
-
- let current = this.getHead(),
- string = '';
-
- while (current) {
- string += current.element + (current.next ? ', ' : '');
- current = current.next;
- }
- return string;
-
- }
-
- print() {
- console.log(this.toString());
- }
- }
-
- return LinkedList2;
-})();
diff --git a/chapter05/02-UsingLinkedLists.html b/chapter05/02-UsingLinkedLists.html
deleted file mode 100644
index 97210e70..00000000
--- a/chapter05/02-UsingLinkedLists.html
+++ /dev/null
@@ -1,12 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/chapter05/02-UsingLinkedLists.js b/chapter05/02-UsingLinkedLists.js
deleted file mode 100644
index bef9d86e..00000000
--- a/chapter05/02-UsingLinkedLists.js
+++ /dev/null
@@ -1,32 +0,0 @@
-let list = new LinkedList2();
-list.append(15);
-list.print();
-console.log(list.indexOf(15));
-list.append(10);
-list.print();
-console.log(list.indexOf(10));
-list.append(13);
-list.print();
-console.log(list.indexOf(13));
-console.log(list.indexOf(10));
-list.append(11);
-list.append(12);
-list.print();
-console.log(list.removeAt(1));
-list.print()
-console.log(list.removeAt(3));
-list.print();
-list.append(14);
-list.print();
-list.insert(0,16);
-list.print();
-list.insert(1,17);
-list.print();
-list.insert(list.size(),18);
-list.print();
-list.remove(16);
-list.print();
-list.remove(11);
-list.print();
-list.remove(18);
-list.print();
\ No newline at end of file
diff --git a/chapter05/03-DoublyLinkedList.js b/chapter05/03-DoublyLinkedList.js
deleted file mode 100644
index 6d4de9c5..00000000
--- a/chapter05/03-DoublyLinkedList.js
+++ /dev/null
@@ -1,217 +0,0 @@
-function DoublyLinkedList() {
-
- let Node = function(element){
-
- this.element = element;
- this.next = null;
- this.prev = null; //NEW
- };
-
- let length = 0;
- let head = null;
- let tail = null; //NEW
-
- this.append = function(element){
-
- let node = new Node(element),
- current;
-
- if (head === null){ //first node on list
- head = node;
- tail = node; //NEW
- } else {
-
- //attach to the tail node //NEW
- tail.next = node;
- node.prev = tail;
- tail = node;
- }
-
- length++; //update size of list
- };
-
- this.insert = function(position, element){
-
- //check for out-of-bounds values
- if (position >= 0 && position <= length){
-
- let node = new Node(element),
- current = head,
- previous,
- index = 0;
-
- if (position === 0){ //add on first position
-
- if (!head){ //NEW
- head = node;
- tail = node;
- } else {
- node.next = current;
- current.prev = node; //NEW {1}
- head = node;
- }
-
- } else if (position === length) { //last item //NEW
-
- current = tail; // {2}
- current.next = node;
- node.prev = current;
- tail = node;
-
- } else {
- while (index++ < position){ //{3}
- previous = current;
- current = current.next;
- }
- node.next = current;
- previous.next = node;
-
- current.prev = node; //NEW
- node.prev = previous; //NEW
- }
-
- length++; //update size of list
-
- return true;
-
- } else {
- return false;
- }
- };
-
- this.removeAt = function(position){
-
- //check for out-of-bounds values
- if (position > -1 && position < length){
-
- let current = head,
- previous,
- index = 0;
-
- //removing first item
- if (position === 0){
-
- head = current.next; // {1}
-
- //if there is only one item, then we update tail as well //NEW
- if (length === 1){ // {2}
- tail = null;
- } else {
- head.prev = null; // {3}
- }
-
- } else if (position === length-1){ //last item //NEW
-
- current = tail; // {4}
- tail = current.prev;
- tail.next = null;
-
- } else {
-
- while (index++ < position){ // {5}
-
- previous = current;
- current = current.next;
- }
-
- //link previous with current's next - skip it to remove
- previous.next = current.next; // {6}
- current.next.prev = previous; //NEW
- }
-
- length--;
-
- return current.element;
-
- } else {
- return null;
- }
- };
-
- this.remove = function(element){
-
- let index = this.indexOf(element);
- return this.removeAt(index);
- };
-
- this.indexOf = function(element){
-
- let current = head,
- index = -1;
-
- //check first item
- if (element == current.element){
- return 0;
- }
-
- index++;
-
- //check in the middle of the list
- while(current.next){
-
- if (element == current.element){
- return index;
- }
-
- current = current.next;
- index++;
- }
-
- //check last item
- if (element == current.element){
- return index;
- }
-
- return -1;
- };
-
- this.isEmpty = function() {
- return length === 0;
- };
-
- this. size = function() {
- return length;
- };
-
- this.toString = function(){
-
- let current = head,
- s = current ? current.element : '';
-
- while(current && current.next){
- current = current.next;
- s += ', ' + current.element;
- }
-
- return s;
- };
-
- this.inverseToString = function() {
-
- let current = tail,
- s = current ? current.element : '';
-
- while(current && current.prev){
- current = current.prev;
- s += ', ' + current.element;
- }
-
- return s;
- };
-
- this.print = function(){
- console.log(this.toString());
- };
-
- this.printInverse = function(){
- console.log(this.inverseToString());
- };
-
- this.getHead = function(){
- return head;
- };
-
- this.getTail = function(){
- return tail;
- }
-}
\ No newline at end of file
diff --git a/chapter05/03-DoublyLinkedList2.js b/chapter05/03-DoublyLinkedList2.js
deleted file mode 100644
index 9fe7d87b..00000000
--- a/chapter05/03-DoublyLinkedList2.js
+++ /dev/null
@@ -1,242 +0,0 @@
-let DoublyLinkedList2 = (function () {
-
- class Node {
- constructor(element) {
- this.element = element;
- this.next = null;
- this.prev = null; //NEW
- }
- }
-
- const length = new WeakMap();
- const head = new WeakMap();
- const tail = new WeakMap(); //NEW
-
- class DoublyLinkedList2 {
-
- constructor () {
- length.set(this, 0);
- head.set(this, null);
- tail.set(this, null);
- }
-
- append(element) {
-
- let node = new Node(element),
- current, _tail;
-
- if (this.getHead() === null) { //first node on list
- head.set(this, node);
- tail.set(this, node); //NEW
- } else {
- //attach to the tail node //NEW
- _tail = this.getTail();
- _tail.next = node;
- node.prev = _tail;
- tail.set(this, node);
- }
-
- //update size of list
- let l = this.size();
- l++;
- length.set(this, l);
- }
-
- insert(position, element) {
-
- //check for out-of-bounds values
- if (position >= 0 && position <= this.size()) {
-
- let node = new Node(element),
- current = this.getHead(),
- previous,
- index = 0;
-
- if (position === 0) { //add on first position
-
- if (!this.getHead()) { //NEW
- head.set(this, node);
- tail.set(this, node);
- } else {
- node.next = current;
- current.prev = node; //NEW {1}
- head.set(this, node);
- }
-
- } else if (position === this.size()) { //last item //NEW
-
- current = tail; // {2}
- current.next = node;
- node.prev = current;
- tail.set(this, node);
-
- } else {
- while (index++ < position) { //{3}
- previous = current;
- current = current.next;
- }
- node.next = current;
- previous.next = node;
-
- current.prev = node; //NEW
- node.prev = previous; //NEW
- }
-
- //update size of list
- let l = this.size();
- l++;
- length.set(this, l);
-
- return true;
-
- } else {
- return false;
- }
- }
-
- removeAt(position) {
-
- //check for out-of-bounds values
- if (position > -1 && position < this.size()) {
-
- let _head = this.getHead(),
- _tail = this.getTail(),
- current = _head,
- previous,
- index = 0;
-
- //removing first item
- if (position === 0) {
-
- _head = current.next; // {1}
-
- //if there is only one item, then we update tail as well //NEW
- if (this.size() === 1) { // {2}
- _tail = null;
- } else {
- _head.prev = null; // {3}
- }
-
- } else if (position === this.size() - 1) { //last item //NEW
-
- current = _tail; // {4}
- _tail = current.prev;
- _tail.next = null;
-
- } else {
-
- while (index++ < position) { // {5}
-
- previous = current;
- current = current.next;
- }
-
- //link previous with current's next - skip it to remove
- previous.next = current.next; // {6}
- current.next.prev = previous; //NEW
- }
-
- head.set(this,_head);
- tail.set(this,_tail);
-
- //update size of list
- let l = this.size();
- l--;
- length.set(this, l);
-
- return current.element;
-
- } else {
- return null;
- }
- }
-
- remove(element) {
-
- let index = this.indexOf(element);
- return this.removeAt(index);
- }
-
- indexOf(element) {
-
- let current = this.getHead(),
- index = -1;
-
- //check first item
- if (element == current.element) {
- return 0;
- }
-
- index++;
-
- //check in the middle of the list
- while (current.next) {
-
- if (element == current.element) {
- return index;
- }
-
- current = current.next;
- index++;
- }
-
- //check last item
- if (element == current.element) {
- return index;
- }
-
- return -1;
- }
-
- isEmpty() {
- return this.size() === 0;
- }
-
- size() {
- return length.get(this);
- }
-
- toString() {
-
- let current = this.getHead(),
- s = current ? current.element : '';
-
- while (current && current.next) {
- current = current.next;
- s += ', ' + current.element;
- }
-
- return s;
- }
-
- inverseToString() {
-
- let current = this.getTail(),
- s = current ? current.element : '';
-
- while (current && current.prev) {
- current = current.prev;
- s += ', ' + current.element;
- }
-
- return s;
- }
-
- print() {
- console.log(this.toString());
- }
-
- printInverse() {
- console.log(this.inverseToString());
- }
-
- getHead() {
- return head.get(this);
- }
-
- getTail() {
- return tail.get(this);
- }
- }
- return DoublyLinkedList2;
-})();
\ No newline at end of file
diff --git a/chapter05/04-UsingDoublyLinkedLists.html b/chapter05/04-UsingDoublyLinkedLists.html
deleted file mode 100644
index 58f959d5..00000000
--- a/chapter05/04-UsingDoublyLinkedLists.html
+++ /dev/null
@@ -1,12 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/chapter05/04-UsingDoublyLinkedLists.js b/chapter05/04-UsingDoublyLinkedLists.js
deleted file mode 100644
index 9ad4a17c..00000000
--- a/chapter05/04-UsingDoublyLinkedLists.js
+++ /dev/null
@@ -1,49 +0,0 @@
-let list = new DoublyLinkedList2();
-
-list.append(15);
-list.print();
-list.printInverse();
-
-list.append(16);
-list.print();
-list.printInverse();
-
-list.append(17);
-list.print();
-list.printInverse();
-
-list.insert(0,13);
-list.print();
-list.printInverse();
-
-list.insert(4,18);
-list.print();
-list.printInverse();
-
-list.insert(1,14);
-list.print();
-list.printInverse();
-
-list.removeAt(0);
-list.print();
-list.printInverse();
-
-list.removeAt(list.size()-1);
-list.print();
-list.printInverse();
-
-list.removeAt(1);
-list.print();
-list.printInverse();
-
-list.remove(16);
-list.print();
-list.printInverse();
-
-list.remove(14);
-list.print();
-list.printInverse();
-
-list.remove(17);
-list.print();
-list.printInverse();
\ No newline at end of file
diff --git a/chapter05/05-CircularLinkedList.js b/chapter05/05-CircularLinkedList.js
deleted file mode 100644
index c3151148..00000000
--- a/chapter05/05-CircularLinkedList.js
+++ /dev/null
@@ -1,190 +0,0 @@
-function CircularLinkedList() {
-
- let Node = function(element){
-
- this.element = element;
- this.next = null;
- };
-
- let length = 0;
- let head = null;
-
- this.append = function(element){
-
- let node = new Node(element),
- current;
-
- if (head === null){ //first node on list
- head = node;
- } else {
-
- current = head;
-
- //loop the list until find last item
- while(current.next !== head){ //last element will be head instead of NULL
- current = current.next;
- }
-
- //get last item and assign next to added item to make the link
- current.next = node;
- }
-
- //set node.next to head - to have circular list
- node.next = head;
-
- length++; //update size of list
- };
-
- this.insert = function(position, element){
-
- //check for out-of-bounds values
- if (position >= 0 && position <= length){
-
- let node = new Node(element),
- current = head,
- previous,
- index = 0;
-
- if (position === 0){ //add on first position
-
- 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;
- }
-
-
- } else {
- while (index++ < position){
- previous = current;
- current = current.next;
- }
- node.next = current;
- previous.next = node;
- }
-
- length++; //update size of list
-
- return true;
-
- } else {
- return false;
- }
- };
-
- this.removeAt = function(position){
-
- //check for out-of-bounds values
- if (position > -1 && position < length){
-
- let current = head,
- previous,
- index = 0;
-
- //removing first item
- if (position === 0){
-
- while(current.next !== head){ //needs to update last element first
- current = current.next;
- }
-
- head = head.next;
- current.next = head;
-
- } else { //no need to update last element for circular list
-
- while (index++ < position){
-
- previous = current;
- current = current.next;
- }
-
- //link previous with current's next - skip it to remove
- previous.next = current.next;
- }
-
- length--;
-
- return current.element;
-
- } else {
- return null;
- }
- };
-
- this.remove = function(element){
-
- let index = this.indexOf(element);
- return this.removeAt(index);
- };
-
- this.indexOf = function(element){
-
- let current = head,
- index = -1;
-
- //check first item
- if (element == current.element){
- return 0;
- }
-
- index++;
-
- //check in the middle of the list
- while(current.next !== head){
-
- if (element == current.element){
- return index;
- }
-
- current = current.next;
- index++;
- }
-
- //check last item
- if (element == current.element){
- return index;
- }
-
- return -1;
- };
-
- this.isEmpty = function() {
- return length === 0;
- };
-
- this.size = function() {
- return length;
- };
-
- this.getHead = function(){
- return head;
- };
-
- this.toString = function(){
-
- let current = head,
- s = current.element;
-
- while(current.next !== head){
- current = current.next;
- s += ', ' + current.element;
- }
-
- return s.toString();
- };
-
- this.print = function(){
- console.log(this.toString());
- };
-}
-
diff --git a/chapter05/05-CircularLinkedList2.js b/chapter05/05-CircularLinkedList2.js
deleted file mode 100644
index 6f7574ef..00000000
--- a/chapter05/05-CircularLinkedList2.js
+++ /dev/null
@@ -1,204 +0,0 @@
-let CircularLinkedList2 = (function () {
-
- class Node {
- constructor(element) {
- this.element = element;
- this.next = null;
- }
- }
-
- const length = new WeakMap();
- const head = new WeakMap();
-
- class CircularLinkedList2 {
-
- constructor () {
- length.set(this, 0);
- head.set(this, null);
- }
-
- append(element) {
-
- let node = new Node(element),
- current;
-
- if (this.getHead() === null) { //first node on list
- head.set(this, node);
- } else {
-
- current = this.getHead();
-
- //loop the list until find last item
- while (current.next !== this.getHead()) { //last element will be head instead of NULL
- current = current.next;
- }
-
- //get last item and assign next to added item to make the link
- current.next = node;
- }
-
- //set node.next to head - to have circular list
- node.next = this.getHead();
-
- //update size of list
- let l = this.size();
- l++;
- length.set(this, l);
- }
-
- insert(position, element) {
-
- //check for out-of-bounds values
- if (position >= 0 && position <= this.size()) {
-
- let node = new Node(element),
- current = this.getHead(),
- previous,
- index = 0;
-
- if (position === 0) { //add on first position
-
- 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) {
- previous = current;
- current = current.next;
- }
- node.next = current;
- previous.next = node;
- }
-
- //update size of list
- let l = this.size();
- l++;
- length.set(this, l);
-
- return true;
-
- } else {
- return false;
- }
- }
-
- removeAt(position) {
-
- //check for out-of-bounds values
- if (position > -1 && position < this.size()) {
-
- let current = this.getHead(),
- previous,
- index = 0;
-
- //removing first item
- if (position === 0) {
-
- while (current.next !== this.getHead()) { //needs to update last element first
- current = current.next;
- }
-
- head.set(this, this.getHead().next);
- current.next = this.getHead();
-
- } else { //no need to update last element for circular list
-
- while (index++ < position) {
-
- previous = current;
- current = current.next;
- }
-
- //link previous with current's next - skip it to remove
- previous.next = current.next;
- }
-
- let l = this.size();
- l--;
- length.set(this, l);
-
- return current.element;
-
- } else {
- return null;
- }
- }
-
- remove(element) {
-
- let index = this.indexOf(element);
- return this.removeAt(index);
- }
-
- indexOf(element) {
-
- let current = this.getHead(),
- index = -1;
-
- //check first item
- if (element == current.element) {
- return 0;
- }
-
- index++;
-
- //check in the middle of the list
- while (current.next !== this.getHead()) {
-
- if (element == current.element) {
- return index;
- }
-
- current = current.next;
- index++;
- }
-
- //check last item
- if (element == current.element) {
- return index;
- }
-
- return -1;
- }
-
- isEmpty() {
- return this.size() === 0;
- }
-
- size() {
- return length.get(this);
- }
-
- getHead() {
- return head.get(this);
- }
-
- toString() {
-
- let current = this.getHead(),
- s = current.element;
-
- while (current.next !== this.getHead()) {
- current = current.next;
- s += ', ' + current.element;
- }
-
- return s.toString();
- }
-
- print() {
- console.log(this.toString());
- }
- }
- return CircularLinkedList2;
-})();
diff --git a/chapter05/06-UsingCircularLinkedList.html b/chapter05/06-UsingCircularLinkedList.html
deleted file mode 100644
index ab39ba27..00000000
--- a/chapter05/06-UsingCircularLinkedList.html
+++ /dev/null
@@ -1,12 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/chapter05/06-UsingCircularLinkedList.js b/chapter05/06-UsingCircularLinkedList.js
deleted file mode 100644
index a1feebbb..00000000
--- a/chapter05/06-UsingCircularLinkedList.js
+++ /dev/null
@@ -1,28 +0,0 @@
-let circularLinkedList = new CircularLinkedList2();
-
-circularLinkedList.append(15);
-circularLinkedList.print();
-
-circularLinkedList.append(16);
-circularLinkedList.print();
-
-circularLinkedList.insert(0,14);
-circularLinkedList.print();
-
-circularLinkedList.insert(1,14.5);
-circularLinkedList.print();
-
-circularLinkedList.insert(4,17);
-circularLinkedList.print();
-
-circularLinkedList.removeAt(0);
-circularLinkedList.print();
-
-circularLinkedList.removeAt(1);
-circularLinkedList.print();
-
-circularLinkedList.removeAt(2);
-circularLinkedList.print();
-
-console.log(circularLinkedList.indexOf(14.5));
-console.log(circularLinkedList.indexOf(16));
\ No newline at end of file
diff --git a/chapter06/01-Set.js b/chapter06/01-Set.js
deleted file mode 100644
index 3fa90281..00000000
--- a/chapter06/01-Set.js
+++ /dev/null
@@ -1,142 +0,0 @@
-/**
- * ECMSCRIPT 6 already have a Set class implementation:
- * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
- * We will try to copy the same functionalities
- * @constructor
- */
-function Set() {
-
- let items = {};
-
- this.add = function(value){
- if (!this.has(value)){
- items[value] = value;
- return true;
- }
- return false;
- };
-
- this.delete = function(value){
- if (this.has(value)){
- delete items[value];
- return true;
- }
- return false;
- };
-
- this.has = function(value){
- return items.hasOwnProperty(value);
- //return value in items;
- };
-
- this.clear = function(){
- items = {};
- };
-
- /**
- * Modern browsers function
- * IE9+, FF4+, Chrome5+, Opera12+, Safari5+
- * @returns {Number}
- */
- this.size = function(){
- return Object.keys(items).length;
- };
-
- /**
- * cross browser compatibility - legacy browsers
- * for modern browsers use size function
- * @returns {number}
- */
- this.sizeLegacy = function(){
- let count = 0;
- for(let key in items) {
- if(items.hasOwnProperty(key))
- ++count;
- }
- return count;
- };
-
- /**
- * Modern browsers function
- * IE9+, FF4+, Chrome5+, Opera12+, Safari5+
- * @returns {Array}
- */
- this.values = function(){
- let values = [];
- for (let i=0, keys=Object.keys(items); i otherSet.size()){ //{1}
- return false;
- } else {
- let values = this.values();
- for (let i=0; i otherSet.size()){
- return false;
- } else {
- let values = this.values();
- for (let i=0; i
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/chapter06/02-UsingSets.js b/chapter06/02-UsingSets.js
deleted file mode 100644
index e74269ac..00000000
--- a/chapter06/02-UsingSets.js
+++ /dev/null
@@ -1,18 +0,0 @@
-let set = new Set();
-
-set.add(1);
-console.log(set.values()); //outputs [1]
-console.log(set.has(1)); //outputs true
-console.log(set.size()); //outputs 1
-
-set.add(2);
-console.log(set.values()); //outputs [1, 2]
-console.log(set.has(2)); //true
-console.log(set.size()); //2
-console.log(set.sizeLegacy()); //3
-
-set.delete(1);
-console.log(set.values()); //outputs [2]
-
-set.delete(2);
-console.log(set.values()); //outputs []
\ No newline at end of file
diff --git a/chapter06/03-Operations.js b/chapter06/03-Operations.js
deleted file mode 100644
index dc7ece35..00000000
--- a/chapter06/03-Operations.js
+++ /dev/null
@@ -1,65 +0,0 @@
-//--------- Union ----------
-
-let setA = new Set();
-setA.add(1);
-setA.add(2);
-setA.add(3);
-
-let setB = new Set();
-setB.add(3);
-setB.add(4);
-setB.add(5);
-setB.add(6);
-
-let unionAB = setA.union(setB);
-console.log(unionAB.values());
-
-
-//--------- Intersection ----------
-
-let setA = new Set();
-setA.add(1);
-setA.add(2);
-setA.add(3);
-
-let setB = new Set();
-setB.add(2);
-setB.add(3);
-setB.add(4);
-
-let intersectionAB = setA.intersection(setB);
-console.log(intersectionAB.values());
-
-//--------- Difference ----------
-
-let setA = new Set();
-setA.add(1);
-setA.add(2);
-setA.add(3);
-
-let setB = new Set();
-setB.add(2);
-setB.add(3);
-setB.add(4);
-
-let differenceAB = setA.difference(setB);
-console.log(differenceAB.values());
-
-//--------- Subset ----------
-
-let setA = new Set();
-setA.add(1);
-setA.add(2);
-
-let setB = new Set();
-setB.add(1);
-setB.add(2);
-setB.add(3);
-
-let setC = new Set();
-setC.add(2);
-setC.add(3);
-setC.add(4);
-
-console.log(setA.subset(setB));
-console.log(setA.subset(setC));
diff --git a/chapter06/04-UsingES6Set.js b/chapter06/04-UsingES6Set.js
deleted file mode 100644
index a39e4100..00000000
--- a/chapter06/04-UsingES6Set.js
+++ /dev/null
@@ -1,71 +0,0 @@
-let set = new Set();
-
-set.add(1);
-console.log(set.values()); //outputs @Iterator
-console.log(set.has(1)); //outputs true
-console.log(set.size); //outputs 1
-
-set.add(2);
-console.log(set.values()); //outputs [1, 2]
-console.log(set.has(2)); //true
-console.log(set.size); //2
-
-set.delete(1);
-console.log(set.values()); //outputs [2]
-
-set.delete(2);
-console.log(set.values()); //outputs []
-
-let setA = new Set();
-setA.add(1);
-setA.add(2);
-setA.add(3);
-
-let setB = new Set();
-setB.add(2);
-setB.add(3);
-setB.add(4);
-
-//--------- Union ----------
-let unionAb = new Set();
-for (let x of setA) unionAb.add(x);
-for (let x of setB) unionAb.add(x);
-console.log(unionAb);
-
-//--------- Intersection ----------
-let intersection = function(setA, setB){
- let intersectionSet = new Set();
-
- for (let x of setA){
- if (setB.has(x)){
- intersectionSet.add(x);
- }
- }
-
- return intersectionSet;
-};
-let intersectionAB = intersection(setA, setB);
-console.log(intersectionAB);
-
-//alternative - works on FF only
-//intersectionAb = new Set([x for (x of setA) if (setB.has(x))]);
-//console.log(intersectionAB);
-
-//--------- Difference ----------
-let difference = function(setA, setB){
- let differenceSet = new Set();
-
- for (let x of setA){
- if (!setB.has(x)){
- differenceSet.add(x);
- }
- }
-
- return differenceSet;
-};
-let differenceAB = difference(setA, setB);
-console.log(differenceAB);
-
-//alternative - works on FF only
-//differenceAB = new Set([x for (x of setA) if (!setB.has(x))]);
-//console.log(differenceAB);
diff --git a/chapter07/01-Dictionaries.js b/chapter07/01-Dictionaries.js
deleted file mode 100644
index a22ec419..00000000
--- a/chapter07/01-Dictionaries.js
+++ /dev/null
@@ -1,59 +0,0 @@
-function Dictionary(){
-
- var items = {};
-
- this.set = function(key, value){
- items[key] = value; //{1}
- };
-
- this.delete = function(key){
- if (this.has(key)){
- delete items[key];
- return true;
- }
- return false;
- };
-
- this.has = function(key){
- return items.hasOwnProperty(key);
- //return value in items;
- };
-
- this.get = function(key) {
- return this.has(key) ? items[key] : undefined;
- };
-
- this.clear = function(){
- items = {};
- };
-
- this.size = function(){
- return Object.keys(items).length;
- };
-
- this.keys = function(){
- return Object.keys(items);
- };
-
- this.values = function(){
- var values = [];
- for (var k in items) {
- if (this.has(k)) {
- values.push(items[k]);
- }
- }
- return values;
- };
-
- this.each = function(fn) {
- for (var k in items) {
- if (this.has(k)) {
- fn(k, items[k]);
- }
- }
- };
-
- this.getItems = function(){
- return items;
- }
-}
\ No newline at end of file
diff --git a/chapter07/02-UsingDictionaries.js b/chapter07/02-UsingDictionaries.js
deleted file mode 100644
index dc0bf258..00000000
--- a/chapter07/02-UsingDictionaries.js
+++ /dev/null
@@ -1,19 +0,0 @@
-var dictionary = new Dictionary();
-
-dictionary.set('Gandalf', 'gandalf@email.com');
-dictionary.set('John', 'johnsnow@email.com');
-dictionary.set('Tyrion', 'tyrion@email.com');
-
-console.log(dictionary.has('Gandalf')); //outputs true
-console.log(dictionary.size()); //outputs 3
-
-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');
-
-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"}
diff --git a/chapter07/05-HashCollisionSeparateChaining.js b/chapter07/05-HashCollisionSeparateChaining.js
deleted file mode 100644
index 5cac0e7d..00000000
--- a/chapter07/05-HashCollisionSeparateChaining.js
+++ /dev/null
@@ -1,85 +0,0 @@
-function HashTableSeparateChaining(){
-
- var table = [];
-
- var ValuePair = function(key, value){
- this.key = key;
- this.value = value;
-
- this.toString = function() {
- return '[' + this.key + ' - ' + this.value + ']';
- }
- };
-
- var loseloseHashCode = function (key) {
- var hash = 0;
- for (var i = 0; i < key.length; i++) {
- hash += key.charCodeAt(i);
- }
- return hash % 37;
- };
-
- var hashCode = function(key){
- return loseloseHashCode(key);
- };
-
- this.put = function(key, value){
- var position = hashCode(key);
- console.log(position + ' - ' + key);
-
- if (table[position] == undefined) {
- table[position] = new LinkedList();
- }
- table[position].append(new ValuePair(key, value));
- };
-
- this.get = function(key) {
- var position = hashCode(key);
-
- if (table[position] !== undefined && !table[position].isEmpty()){
-
- //iterate linked list to find key/value
- var current = table[position].getHead();
-
- do {
- if (current.element.key === key){
- return current.element.value;
- }
- current = current.next;
- } while(current);
- }
- return undefined;
- };
-
- this.remove = function(key){
-
- var position = hashCode(key);
-
- if (table[position] !== undefined){
-
- //iterate linked list to find key/value
- var current = table[position].getHead();
-
- do {
- if (current.element.key === key){
- table[position].remove(current.element);
- if (table[position].isEmpty()){
- table[position] = undefined;
- }
- return true;
- }
- current = current.next;
- } while(current);
- }
-
- return false;
- };
-
- this.print = function() {
- for (var i = 0; i < table.length; ++i) {
- if (table[i] !== undefined) {
- console.log(table[i].toString());
- }
- }
- };
-}
\ No newline at end of file
diff --git a/chapter07/06-UsingHashCollisionSeparateChaining.html b/chapter07/06-UsingHashCollisionSeparateChaining.html
deleted file mode 100644
index d671e133..00000000
--- a/chapter07/06-UsingHashCollisionSeparateChaining.html
+++ /dev/null
@@ -1,12 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/chapter07/07-HashCollisionLinearProbing.js b/chapter07/07-HashCollisionLinearProbing.js
deleted file mode 100644
index 4b1172be..00000000
--- a/chapter07/07-HashCollisionLinearProbing.js
+++ /dev/null
@@ -1,94 +0,0 @@
-function HashLinearProbing(){
-
- var table = [];
-
- var ValuePair = function(key, value){
- this.key = key;
- this.value = value;
-
- this.toString = function() {
- return '[' + this.key + ' - ' + this.value + ']';
- }
- };
-
- var loseloseHashCode = function (key) {
- var hash = 0;
- for (var i = 0; i < key.length; i++) {
- hash += key.charCodeAt(i);
- }
- return hash % 37;
- };
-
- var hashCode = function(key){
- return loseloseHashCode(key);
- };
-
- this.put = function(key, value){
- var position = hashCode(key);
- console.log(position + ' - ' + key);
-
- if (table[position] == undefined) {
- table[position] = new ValuePair(key, value);
- } else {
- var index = ++position;
- while (table[index] != undefined){
- index++;
- }
- table[index] = new ValuePair(key, value);
- }
- };
-
- this.get = function(key) {
- var position = hashCode(key);
-
- if (table[position] !== undefined){
- if (table[position].key === key) {
- return table[position].value;
- } else {
- var index = ++position;
- while (table[index] !== undefined && (table[index] && table[index].key !== key)){
- index++;
- }
- if (table[index] && table[index].key === key) {
- 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;
- };
-
- this.remove = function(key){
- var position = hashCode(key);
-
- if (table[position] !== undefined){
- if (table[position].key === key) {
- table[position] = undefined;
- } else {
- var index = ++position;
- while (table[index] === undefined || table[index].key !== key){
- index++;
- }
- if (table[index].key === key) {
- table[index] = undefined;
- }
- }
- }
- };
-
- this.print = function() {
- for (var i = 0; i < table.length; ++i) {
- if (table[i] !== undefined) {
- console.log(i + ' -> ' + table[i].toString());
- }
- }
- };
-}
diff --git a/chapter07/08-UsingHashCollisionLinearProbing.js b/chapter07/08-UsingHashCollisionLinearProbing.js
deleted file mode 100644
index 36a33e61..00000000
--- a/chapter07/08-UsingHashCollisionLinearProbing.js
+++ /dev/null
@@ -1,37 +0,0 @@
-var hashLinearProbing = new HashLinearProbing();
-
-hashLinearProbing.put('Gandalf', 'gandalf@email.com');
-hashLinearProbing.put('John', 'johnsnow@email.com');
-hashLinearProbing.put('Tyrion', 'tyrion@email.com');
-hashLinearProbing.put('Aaron', 'aaron@email.com');
-hashLinearProbing.put('Donnie', 'donnie@email.com');
-hashLinearProbing.put('Ana', 'ana@email.com');
-hashLinearProbing.put('Jonathan', 'jonathan@email.com');
-hashLinearProbing.put('Jamie', 'jamie@email.com');
-hashLinearProbing.put('Sue', 'sue@email.com');
-hashLinearProbing.put('Mindy', 'mindy@email.com');
-hashLinearProbing.put('Paul', 'paul@email.com');
-hashLinearProbing.put('Nathan', 'nathan@email.com');
-
-console.log('**** Printing Hash **** ');
-
-hashLinearProbing.print();
-
-console.log('**** Get **** ');
-
-console.log(hashLinearProbing.get('Nathan'));
-console.log(hashLinearProbing.get('Loiane'));
-
-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
diff --git a/chapter07/09-ES6Map.js b/chapter07/09-ES6Map.js
deleted file mode 100644
index 5e0c9dae..00000000
--- a/chapter07/09-ES6Map.js
+++ /dev/null
@@ -1,17 +0,0 @@
-var map = new Map();
-
-map.set('Gandalf', 'gandalf@email.com');
-map.set('John', 'johnsnow@email.com');
-map.set('Tyrion', 'tyrion@email.com');
-
-console.log(map.has('Gandalf')); //outputs true
-console.log(map.size); //outputs 3
-
-console.log(map.keys()); //outputs ["Gandalf", "John", "Tyrion"]
-console.log(map.values()); //outputs ["gandalf@email.com", "johnsnow@email.com", "tyrion@email.com"]
-console.log(map.get('Tyrion')); //outputs tyrion@email.com
-
-map.delete('John');
-
-console.log(map.keys()); //outputs ["Gandalf", "Tyrion"]
-console.log(map.values()); //outputs ["gandalf@email.com", "tyrion@email.com"]
\ No newline at end of file
diff --git a/chapter07/10-ES6WeakMap.js b/chapter07/10-ES6WeakMap.js
deleted file mode 100644
index 8efa16b8..00000000
--- a/chapter07/10-ES6WeakMap.js
+++ /dev/null
@@ -1,18 +0,0 @@
-var map = new WeakMap();
-
-var ob1 = {name:'Gandalf'},
- ob2 = {name:'John'},
- ob3 = {name:'Tyrion'};
-
-map.set(ob1, 'gandalf@email.com');
-map.set(ob2, 'johnsnow@email.com');
-map.set(ob3, 'tyrion@email.com');
-
-console.log(map.has(ob1)); //outputs true
-console.log(map.has(ob2)); //outputs true
-console.log(map.has(ob3)); //outputs true
-
-console.log(map.get(ob3)); //outputs tyrion@email.com
-
-map.delete(ob2);
-console.log(map.has(ob2)); //outputs false
diff --git a/chapter07/11-ES6WeakSet.js b/chapter07/11-ES6WeakSet.js
deleted file mode 100644
index e54a40de..00000000
--- a/chapter07/11-ES6WeakSet.js
+++ /dev/null
@@ -1,16 +0,0 @@
-var set = new WeakSet();
-
-var ob1 = {name:'Gandalf'},
- ob2 = {name:'John'},
- ob3 = {name:'Tyrion'};
-
-set.add(ob1);
-set.add(ob2);
-set.add(ob3);
-
-console.log(set.has(ob1)); //outputs true
-console.log(set.has(ob2)); //outputs true
-console.log(set.has(ob3)); //outputs true
-
-set.delete(ob2);
-console.log(set.has(ob2)); //outputs false
diff --git a/chapter08/02-UsingBinarySearchTree.html b/chapter08/02-UsingBinarySearchTree.html
deleted file mode 100644
index dd40cf48..00000000
--- a/chapter08/02-UsingBinarySearchTree.html
+++ /dev/null
@@ -1,11 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/chapter08/02-UsingBinarySearchTree.js b/chapter08/02-UsingBinarySearchTree.js
deleted file mode 100644
index eb139837..00000000
--- a/chapter08/02-UsingBinarySearchTree.js
+++ /dev/null
@@ -1,52 +0,0 @@
-var tree = new BinarySearchTree();
-
-tree.insert(11);
-tree.insert(7);
-tree.insert(15);
-tree.insert(5);
-tree.insert(3);
-tree.insert(9);
-tree.insert(8);
-tree.insert(10);
-tree.insert(13);
-tree.insert(12);
-tree.insert(14);
-tree.insert(20);
-tree.insert(18);
-tree.insert(25);
-tree.insert(6);
-
-console.log('********* in-order transverse ***********');
-function printNode(value){
- console.log(value);
-}
-tree.inOrderTraverse(printNode);
-
-console.log('********* pre-order transverse ***********');
-tree.preOrderTraverse(printNode);
-
-console.log('********* post-order transverse ***********');
-tree.postOrderTraverse(printNode);
-
-
-console.log('********* max and min ***********');
-console.log(tree.max());
-console.log(tree.min());
-console.log(tree.search(1) ? 'Key 1 found.' : 'Key 1 not found.');
-console.log(tree.search(8) ? 'Key 8 found.' : 'Key 8 not found.');
-
-
-console.log('********* remove 6 ***********');
-tree.remove(6);
-tree.inOrderTraverse(printNode);
-
-console.log('********* remove 5 ***********');
-tree.remove(5);
-tree.inOrderTraverse(printNode);
-
-console.log('********* remove 15 ***********');
-tree.remove(15);
-tree.inOrderTraverse(printNode);
-
-console.log('********* raw data structure ***********');
-console.log(tree.getRoot());
diff --git a/chapter08/03-AVLTree.js b/chapter08/03-AVLTree.js
deleted file mode 100644
index 2eed4f3e..00000000
--- a/chapter08/03-AVLTree.js
+++ /dev/null
@@ -1,149 +0,0 @@
-function AVLTree() {
-
- var Node = function(key){
- this.key = key;
- this.left = null;
- this.right = null;
- };
-
- var root = null;
-
- this.getRoot = function(){
- return root;
- };
-
- var heightNode = function(node) {
- if (node === null) {
- return -1;
- } else {
- return Math.max(heightNode(node.left), heightNode(node.right)) + 1;
- }
- };
-
- var rotationLL = function(node) {
- var tmp = node.left;
- node.left = tmp.right;
- tmp.right = node;
-
- return tmp;
- };
-
- var rotationRR = function(node) {
- var tmp = node.right;
- node.right = tmp.left;
- tmp.left = node;
-
- return tmp;
- };
-
- var rotationLR = function(node) {
- node.left = rotationRR(node.left);
- return rotationLL(node);
- };
-
- var rotationRL = function(node) {
- node.right = rotationLL(node.right);
- return rotationRR(node);
- };
-
- var insertNode = function(node, element) {
-
- if (node === null) {
- node = new Node(element);
-
- } else if (element < node.key) {
-
- node.left = insertNode(node.left, element);
-
- if (node.left !== null) {
-
- if ((heightNode(node.left) - heightNode(node.right)) > 1){
- if (element < node.left.key){
- node = rotationLL(node);
- } else {
- node = rotationLR(node);
- }
- }
- }
- } else if (element > node.key) {
-
- node.right = insertNode(node.right, element);
-
- if (node.right !== null) {
-
- if ((heightNode(node.right) - heightNode(node.left)) > 1){
-
- if (element > node.right.key){
- node = rotationRR(node);
- } else {
- node = rotationRL(node);
- }
- }
- }
- }
-
- return node;
- };
-
- this.insert = function(element) {
- root = insertNode(root, element);
- };
-
- var parentNode;
- var nodeToBeDeleted;
-
- var removeNode = function(node, element) {
- if (node === null) {
- return null;
- }
- parentNode = node;
-
- if (element < node.key) {
- node.left = removeNode(node.left, element);
- } else {
- nodeToBeDeleted = node;
- node.right = removeNode(node.right, element);
- }
-
- if (node === parentNode) { //remove node
- if (nodeToBeDeleted !== null && element === nodeToBeDeleted.key) {
- if (nodeToBeDeleted === parentNode) {
- node = node.left;
- } else {
- var tmp = nodeToBeDeleted.key;
- nodeToBeDeleted.key = parentNode.key;
- parentNode.key = tmp;
- node = node.right;
- }
- }
- } else { //do balancing
-
- if (node.left === undefined) node.left = null;
- if (node.right === undefined) node.right = null;
-
- if ((heightNode(node.left) - heightNode(node.right)) === 2) {
- if (element < node.left.key) {
- node = rotationLR(node);
- } else {
- node = rotationLL(node);
- }
- }
-
- if ((heightNode(node.right) - heightNode(node.left)) === 2) {
- if (element > node.right.key) {
- node = rotationRL(node);
- } else {
- node = rotationRR(node);
- }
- }
- }
-
- return node;
- };
-
- this.remove = function(element) {
- parentNode = null;
- nodeToBeDeleted = null;
- root = removeNode(root, element);
- };
-}
\ No newline at end of file
diff --git a/chapter08/04-UsingAVLTree.html b/chapter08/04-UsingAVLTree.html
deleted file mode 100644
index fda15f71..00000000
--- a/chapter08/04-UsingAVLTree.html
+++ /dev/null
@@ -1,11 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/chapter08/04-UsingAVLTree.js b/chapter08/04-UsingAVLTree.js
deleted file mode 100644
index fd77d395..00000000
--- a/chapter08/04-UsingAVLTree.js
+++ /dev/null
@@ -1,62 +0,0 @@
-var avlTree = new AVLTree();
-
-avlTree.insert(1);
-avlTree.insert(2);
-avlTree.insert(3);
-avlTree.insert(4);
-avlTree.insert(5);
-avlTree.insert(6);
-avlTree.insert(7);
-avlTree.insert(14);
-avlTree.insert(15);
-avlTree.insert(13);
-avlTree.insert(12);
-avlTree.insert(11);
-
-//RR rotation
-/*avlTree.insert(50);
-avlTree.insert(30);
-avlTree.insert(70);
-avlTree.insert(60);
-avlTree.insert(80);
-avlTree.insert(90);*/
-
-//LL rotation
-/*avlTree.insert(50);
-avlTree.insert(30);
-avlTree.insert(70);
-avlTree.insert(10);
-avlTree.insert(40);
-avlTree.insert(5);*/
-
-//LR rotation
-/*avlTree.insert(50);
-avlTree.insert(30);
-avlTree.insert(70);
-avlTree.insert(40);
-avlTree.insert(10);
-avlTree.insert(35);*/
-
-//RL rotation
-/*avlTree.insert(70);
-avlTree.insert(50);
-avlTree.insert(80);
-avlTree.insert(72);
-avlTree.insert(90);
-avlTree.insert(75);*/
-
-console.log('********* raw data structure ***********');
-console.log(avlTree.getRoot());
-
-/*avlTree.remove(12);
-avlTree.remove(15);
-avlTree.remove(11);
-avlTree.remove(14);
-avlTree.remove(13);
-avlTree.remove(7);
-avlTree.remove(6);
-avlTree.remove(2);
-avlTree.remove(4);
-
-console.log(avlTree.getRoot());*/
-
diff --git a/chapter08/05-RedBlackTree.js b/chapter08/05-RedBlackTree.js
deleted file mode 100644
index 7a985d2e..00000000
--- a/chapter08/05-RedBlackTree.js
+++ /dev/null
@@ -1,101 +0,0 @@
-function RedBlackTree() {
-
- var Colors = {
- RED: 0,
- BLACK: 1
- };
-
- var Node = function (key, color) {
- this.key = key;
- this.left = null;
- this.right = null;
- this.color = color;
-
- this.flipColor = function(){
- if (this.color === Colors.RED) {
- this.color = Colors.BLACK;
- } else {
- this.color = Colors.RED;
- }
- };
- };
-
- var root = null;
-
- this.getRoot = function () {
- return root;
- };
-
- var isRed = function(node){
- if (!node){
- return false;
- }
- return node.color === Colors.RED;
- };
-
- var flipColors = function(node){
- node.left.flipColor();
- node.right.flipColor();
- };
-
- var rotateLeft = function(node){
- var temp = node.right;
- if (temp !== null) {
- node.right = temp.left;
- temp.left = node;
- temp.color = node.color;
- node.color = Colors.RED;
- }
- return temp;
- };
-
- var rotateRight = function (node) {
- var temp = node.left;
- if (temp !== null) {
- node.left = temp.right;
- temp.right = node;
- temp.color = node.color;
- node.color = Colors.RED;
- }
- return temp;
- };
-
- var insertNode = function(node, element) {
-
- if (node === null) {
- return new Node(element, Colors.RED);
- }
-
- var newRoot = node;
-
- if (element < node.key) {
-
- node.left = insertNode(node.left, element);
-
- } else if (element > node.key) {
-
- node.right = insertNode(node.right, element);
-
- } else {
- node.key = element;
- }
-
- if (isRed(node.right) && !isRed(node.left)) {
- newRoot = rotateLeft(node);
- }
-
- if (isRed(node.left) && isRed(node.left.left)) {
- newRoot = rotateRight(node);
- }
- if (isRed(node.left) && isRed(node.right)) {
- flipColors(node);
- }
-
- return newRoot;
- };
-
- this.insert = function(element) {
- root = insertNode(root, element);
- root.color = Colors.BLACK;
- };
-}
diff --git a/chapter08/06-UsingRedBlackTree.html b/chapter08/06-UsingRedBlackTree.html
deleted file mode 100644
index f0fdfcc9..00000000
--- a/chapter08/06-UsingRedBlackTree.html
+++ /dev/null
@@ -1,11 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/chapter08/06-UsingRedBlackTree.js b/chapter08/06-UsingRedBlackTree.js
deleted file mode 100644
index 31136f99..00000000
--- a/chapter08/06-UsingRedBlackTree.js
+++ /dev/null
@@ -1,17 +0,0 @@
-var rbTree = new RedBlackTree();
-
-rbTree.insert(1);
-rbTree.insert(2);
-rbTree.insert(3);
-rbTree.insert(4);
-rbTree.insert(5);
-rbTree.insert(6);
-rbTree.insert(7);
-rbTree.insert(14);
-rbTree.insert(15);
-rbTree.insert(13);
-rbTree.insert(12);
-rbTree.insert(11);
-
-console.log('********* raw data structure ***********');
-console.log(rbTree.getRoot());
\ No newline at end of file
diff --git a/chapter09/01-Graph.js b/chapter09/01-Graph.js
deleted file mode 100644
index b7a1b847..00000000
--- a/chapter09/01-Graph.js
+++ /dev/null
@@ -1,172 +0,0 @@
-function Graph() {
-
- var vertices = []; //list
-
- var adjList = new Dictionary();
-
- this.addVertex = function(v){
- vertices.push(v);
- adjList.set(v, []); //initialize adjacency list with array as well;
- };
-
- this.addEdge = function(v, w){
- adjList.get(v).push(w);
- //adjList.get(w).push(v); //commented to run the improved DFS with topological sorting
- };
-
- this.toString = function(){
- var s = '';
- for (var i=0; i ';
- var neighbors = adjList.get(vertices[i]);
- for (var j=0; j
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/chapter09/04-UsingShortestPathAlgorithms.js b/chapter09/04-UsingShortestPathAlgorithms.js
deleted file mode 100644
index 5bc5ac79..00000000
--- a/chapter09/04-UsingShortestPathAlgorithms.js
+++ /dev/null
@@ -1,45 +0,0 @@
-//adjacent matrix
-var i;
-
-var graph = [[0, 2, 4, 0, 0, 0],
- [0, 0, 2, 4, 2, 0],
- [0, 0, 0, 0, 3, 0],
- [0, 0, 0, 0, 0, 2],
- [0, 0, 0, 3, 0, 2],
- [0, 0, 0, 0, 0, 0]];
-
-var shortestPath = new ShortestPath(graph);
-
-console.log("********* Dijkstra's Algorithm - Shortest Path ***********");
-
-var dist = shortestPath.dijkstra(0);
-
-for (i = 0; i < dist.length; i++){
- console.log(i + '\t\t' + dist[i]);
-}
-
-console.log("********* Floyd-Warshall Algorithm - All-Pairs Shortest Path ***********");
-
-var INF = Number.MAX_SAFE_INTEGER;
-graph = [[0, 2, 4, INF, INF, INF],
- [INF, 0, 2, 4, 2, INF],
- [INF, INF, 0, INF, 3, INF],
- [INF, INF, INF, 0, INF, 2],
- [INF, INF, INF, 3, 0, 2],
- [INF, INF, INF, INF, INF, 0]];
-
-shortestPath = new ShortestPath(graph);
-
-dist = shortestPath.floydWarshall();
-
-var s = '';
-for (i=0; i
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/chapter09/06-UsingMinimumSpanningTree.js b/chapter09/06-UsingMinimumSpanningTree.js
deleted file mode 100644
index 286f1dff..00000000
--- a/chapter09/06-UsingMinimumSpanningTree.js
+++ /dev/null
@@ -1,29 +0,0 @@
-var i;
-
-var graph = [[0, 2, 4, 0, 0, 0],
- [2, 0, 2, 4, 2, 0],
- [4, 2, 0, 0, 3, 0],
- [0, 4, 0, 0, 3, 2],
- [0, 2, 3, 3, 0, 2],
- [0, 0, 0, 2, 2, 0]];
-
-var mst = new MinimumSpanningTree(graph);
-
-
-console.log("********* Prim's Algorithm - Minimum Spanning Tree ***********");
-
-var parent = mst.prim();
-
-console.log('Edge Weight');
-for (i = 1; i < graph.length; i++){
- console.log(parent[i] + ' - ' + i + ' ' + graph[i][parent[i]]);
-}
-
-console.log("********* Kruskal Algorithm - Minimum Spanning Tree ***********");
-
-parent = mst.kruskal();
-
-console.log('Edge Weight');
-for (i = 1; i < graph.length; i++){
- console.log(parent[i] + ' - ' + i + ' ' + graph[i][parent[i]]);
-}
\ No newline at end of file
diff --git a/chapter10/01-SortingSearchingAlgorithms.js b/chapter10/01-SortingSearchingAlgorithms.js
deleted file mode 100755
index 916e7403..00000000
--- a/chapter10/01-SortingSearchingAlgorithms.js
+++ /dev/null
@@ -1,417 +0,0 @@
-function ArrayList(){
-
- var array = [];
-
- this.insert = function(item){
- array.push(item);
- };
-
- var swap = function(array, index1, index2){
- var aux = array[index1];
- array[index1] = array[index2];
- array[index2] = aux;
- //ES2015 swap - Firefox only, for other browser, uncomment code above and coment line below
- //[array[index1], array[index2]] = [array[index2], array[index1]];
- };
-
- this.toString= function(){
- return array.join();
- };
-
- this.array= function(){
- return array;
- };
-
- this.bubbleSort = function(){
- var length = array.length;
-
- for (var i=0; i array[j+1]){
- console.log('swap ' + array[j] + ' with ' + array[j+1]);
- swap(array, j, j+1);
- }
- }
- }
- };
-
- this.modifiedBubbleSort = function(){
- var length = array.length;
-
- for (var i=0; i array[j+1]){
- console.log('swap ' + array[j] + ' with ' + array[j+1]);
- swap(j, j+1);
- }
- }
- }
-
- };
-
- this.selectionSort = function(){
- var length = array.length,
- indexMin;
-
- for (var i=0; iarray[j]){
- console.log('new index min ' + array[j]);
- indexMin = j;
- }
- }
- if (i !== indexMin){
- console.log('swap ' + array[i] + ' with ' + array[indexMin]);
- swap(i, indexMin);
- }
- }
- };
-
- this.insertionSort = function(){
- var length = array.length,
- j, temp;
- for (var i=1; i0 && array[j-1] > temp){
- console.log('shift ' + array[j-1]);
- array[j] = array[j-1];
- j--;
- }
- console.log('insert ' + temp);
- array[j] = temp;
- }
- };
-
- var insertionSort_ = function(array){
- var length = array.length,
- j, temp;
- for (var i=1; i0 && array[j-1] > temp){
- array[j] = array[j-1];
- j--;
- }
- array[j] = temp;
- }
- };
-
- this.mergeSort = function(){
- array = mergeSortRec(array);
- };
-
- var mergeSortRec = function(array){
-
- var length = array.length;
-
- if(length === 1) {
- console.log(array);
- return array;
- }
-
- var mid = Math.floor(length / 2),
- left = array.slice(0, mid),
- right = array.slice(mid, length);
-
- return merge(mergeSortRec(left), mergeSortRec(right));
- };
-
- var merge = function(left, right){
- var result = [],
- il = 0,
- ir = 0;
-
- while(il < left.length && ir < right.length) {
-
- if(left[il] < right[ir]) {
- result.push(left[il++]);
- } else{
- result.push(right[ir++]);
- }
- }
-
- while (il < left.length){
- result.push(left[il++]);
- }
-
- while (ir < right.length){
- result.push(right[ir++]);
- }
-
- console.log(result);
-
- return result;
- };
-
- this.quickSort = function(){
- quick(array, 0, array.length - 1);
- };
-
- var partition = function(array, left, right) {
-
- var pivot = array[Math.floor((right + left) / 2)],
- i = left,
- j = right;
-
- console.log('pivot is ' + pivot + '; left is ' + left + '; right is ' + right);
-
- while (i <= j) {
- while (array[i] < pivot) {
- i++;
- console.log('i = ' + i);
- }
-
- while (array[j] > pivot) {
- j--;
- console.log('j = ' + j);
- }
-
- if (i <= j) {
- console.log('swap ' + array[i] + ' with ' + array[j]);
- swap(array, i, j);
- i++;
- j--;
- }
- }
-
- return i;
- };
-
- var quick = function(array, left, right){
-
- var index;
-
- if (array.length > 1) {
-
- index = partition(array, left, right);
-
- if (left < index - 1) {
- quick(array, left, index - 1);
- }
-
- if (index < right) {
- quick(array, index, right);
- }
- }
- return array;
- };
-
- this.heapSort = function(){
- var heapSize = array.length;
-
- buildHeap(array);
-
- while (heapSize > 1) {
- heapSize--;
- console.log('swap (' + + array[0] + ',' + array[heapSize] + ')');
- swap(array, 0, heapSize);
- console.log('heapify ' + array.join());
- heapify(array, heapSize, 0);
- }
- };
-
- var buildHeap = function(array){
- console.log('building heap');
- var heapSize = array.length;
- for (var i = Math.floor(array.length / 2); i >= 0; i--) {
- heapify(array, heapSize, i);
- }
- console.log('heap created: ' + array.join());
- };
-
- var heapify = function(array, heapSize, i){
- var left = i * 2 + 1,
- right = i * 2 + 2,
- largest = i;
-
- if (left < heapSize && array[left] > array[largest]) {
- largest = left;
- }
-
- if (right < heapSize && array[right] > array[largest]) {
- largest = right;
- }
-
- console.log('Heapify Index = '+ i + ' and Heap Size = ' + heapSize);
-
- if (largest !== i) {
- console.log('swap index ' + i + ' with ' + largest + ' (' + + array[i] + ',' + array[largest] + ')');
- swap(array, i, largest);
- console.log('heapify ' + array.join());
- heapify(array, heapSize, largest);
- }
- };
-
- this.countingSort = function(){
-
- var i,
- maxValue = this.findMaxValue(),
- sortedIndex = 0,
- counts = new Array(maxValue + 1);
-
- for (i = 0; i < array.length; i++) {
- if (!counts[array[i]]) {
- counts[array[i]] = 0;
- }
- counts[array[i]]++;
- }
-
- console.log('Frequencies: ' + counts.join());
-
- for (i = 0; i < counts.length; i++) {
- while (counts[i] > 0) {
- array[sortedIndex++] = i;
- counts[i]--;
- }
- }
- };
-
- this.bucketSort = function(bucketSize){
-
- var i,
- minValue = this.findMinValue(),
- maxValue = this.findMaxValue(),
- BUCKET_SIZE = 5;
-
- console.log('minValue ' + minValue);
- console.log('maxValue ' + maxValue);
-
- bucketSize = bucketSize || BUCKET_SIZE;
- var bucketCount = Math.floor((maxValue - minValue) / bucketSize) + 1;
- var buckets = new Array(bucketCount);
- console.log('bucketSize = ' + bucketCount);
- for (i = 0; i < buckets.length; i++) {
- buckets[i] = [];
- }
-
- for (i = 0; i < array.length; i++) {
- buckets[Math.floor((array[i] - minValue) / bucketSize)].push(array[i]);
- console.log('pushing item ' + array[i] + ' to bucket index ' + Math.floor((array[i] - minValue) / bucketSize));
- }
-
- array = [];
- for (i = 0; i < buckets.length; i++) {
- insertionSort_(buckets[i]);
-
- console.log('bucket sorted ' + i + ': ' + buckets[i].join());
-
- for (var j = 0; j < buckets[i].length; j++) {
- array.push(buckets[i][j]);
- }
- }
- };
-
- this.radixSort = function(radixBase){
-
- var i,
- minValue = this.findMinValue(),
- maxValue = this.findMaxValue(),
- radixBase = radixBase || 10;
-
- // Perform counting sort for each significant digit), starting at 1
- var significantDigit = 1;
- while (((maxValue - minValue) / significantDigit) >= 1) {
- console.log('radix sort for digit ' + significantDigit);
- array = countingSortForRadix(array, radixBase, significantDigit, minValue);
- console.log(array.join());
- significantDigit *= radixBase;
- }
- };
-
- var countingSortForRadix = function(array, radixBase, significantDigit, minValue){
- var i, countsIndex,
- counts = new Array(radixBase),
- aux = new Array(radixBase);
-
- for (i = 0; i < radixBase; i++) {
- counts[i] = 0;
- }
-
- for (i = 0; i < array.length; i++) {
- countsIndex = Math.floor(((array[i] - minValue) / significantDigit) % radixBase);
- counts[countsIndex]++;
- }
-
- for (i = 1; i < radixBase; i++) {
- counts[i] += counts[i - 1];
- }
-
- for (i = array.length - 1; i >= 0; i--) {
- countsIndex = Math.floor(((array[i] - minValue) / significantDigit) % radixBase);
- aux[--counts[countsIndex]] = array[i];
- }
-
- for (i = 0; i < array.length; i++) {
- array[i] = aux[i];
- }
-
- return array;
- };
-
- this.sequentialSearch = function(item){
-
- for (var i=0; i array[i]){
- min = array[i];
- }
- }
-
- return min;
- };
-
- this.binarySearch = function(item){
- this.quickSort();
-
- var low = 0,
- high = array.length - 1,
- mid, element;
-
- while (low <= high){
- mid = Math.floor((low + high) / 2);
- element = array[mid];
- console.log('mid element is ' + element);
- if (element < item) {
- low = mid + 1;
- console.log('low is ' + low);
- } else if (element > item) {
- high = mid - 1;
- console.log('high is ' + high);
- } else {
- console.log('found it');
- return mid;
- }
- }
- return -1;
- };
-
-}
\ No newline at end of file
diff --git a/chapter10/02-UsingSortingAlgorithms.html b/chapter10/02-UsingSortingAlgorithms.html
deleted file mode 100755
index 7a666fdb..00000000
--- a/chapter10/02-UsingSortingAlgorithms.html
+++ /dev/null
@@ -1,11 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/chapter10/02-UsingSortingAlgorithms.js b/chapter10/02-UsingSortingAlgorithms.js
deleted file mode 100755
index 92b63e8f..00000000
--- a/chapter10/02-UsingSortingAlgorithms.js
+++ /dev/null
@@ -1,126 +0,0 @@
-function createNonSortedArray(size){
- var array = new ArrayList();
-
- for (var i = size; i> 0; i--){
- array.insert(i);
- }
-
- return array;
-}
-
-function createRandomNonSortedArray(){
- var array = new ArrayList();
-
- array.insert(3);
- array.insert(5);
- array.insert(1);
- array.insert(6);
- array.insert(4);
- array.insert(7);
- array.insert(2);
-
- return array;
-}
-
-function printArray(array){
- console.log(array.toString());
-}
-
-function createNonSortedArrayAndPrint(size){
- var array = createNonSortedArray(size);
- printArray(array);
-
- return array;
-}
-
-console.log('********** Bubble Sort **********');
-
-var array = createNonSortedArrayAndPrint(5);
-
-array.bubbleSort();
-
-printArray(array);
-
-console.log('********** Modified Bubble Sort **********');
-
-array = createNonSortedArrayAndPrint(5);
-
-array.modifiedBubbleSort();
-
-printArray(array);
-
-console.log('********** Selection Sort **********');
-
-array = createNonSortedArrayAndPrint(5);
-
-array.selectionSort();
-
-printArray(array);
-
-console.log('********** Insertion Sort **********');
-
-array = createNonSortedArrayAndPrint(5);
-
-array.insertionSort();
-
-printArray(array);
-
-console.log('********** Merge Sort **********');
-
-array = createNonSortedArrayAndPrint(8);
-
-array.mergeSort();
-
-printArray(array);
-
-console.log('********** Quick Sort **********');
-array = createRandomNonSortedArray();
-
-printArray(array);
-
-array.quickSort();
-
-printArray(array);
-
-console.log('********** Heap Sort **********');
-array = createRandomNonSortedArray();
-
-printArray(array);
-
-array.heapSort();
-
-printArray(array);
-
-
-console.log('********** Counting Sort **********');
-
-array = createNonSortedArrayAndPrint(8);
-
-array.countingSort();
-
-printArray(array);
-
-console.log('********** Bucket Sort **********');
-
-array = createNonSortedArrayAndPrint(8);
-
-array.bucketSort(3);
-
-printArray(array);
-
-console.log('********** Radix Sort **********');
-
-var array = new ArrayList();
-
-array.insert(30);
-array.insert(52);
-array.insert(13);
-array.insert(25);
-array.insert(31);
-array.insert(23);
-array.insert(2);
-
-array.radixSort();
-
-console.log('Result: ');
-printArray(array);
diff --git a/chapter10/03-UsingSearchingAlgorithms.html b/chapter10/03-UsingSearchingAlgorithms.html
deleted file mode 100755
index a4e4b6a3..00000000
--- a/chapter10/03-UsingSearchingAlgorithms.html
+++ /dev/null
@@ -1,11 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/chapter10/03-UsingSearchingAlgorithms.js b/chapter10/03-UsingSearchingAlgorithms.js
deleted file mode 100755
index 62201e80..00000000
--- a/chapter10/03-UsingSearchingAlgorithms.js
+++ /dev/null
@@ -1,33 +0,0 @@
-function createNonSortedArray(items){
- var array = new ArrayList();
-
- for (var i = items; i> 0; i--){
- array.insert(i);
- }
-
- return array;
-}
-
-var array = createNonSortedArray(5);
-
-console.log('********** Sequential Sort #3 **********');
-
-console.log(array.sequentialSearch(3));
-
-console.log('********** Min **********');
-
-console.log(array.findMinValue());
-
-console.log('********** Max **********');
-
-console.log(array.findMaxValue());
-
-console.log('********** Binary Search #3 **********');
-
-console.log(array.binarySearch(3));
-
-console.log('********** Binary Search #2 **********');
-
-var array = createNonSortedArray(8);
-
-console.log(array.binarySearch(2));
\ No newline at end of file
diff --git a/chapter11/03-MinCoinChangeDP.js b/chapter11/03-MinCoinChangeDP.js
deleted file mode 100644
index 90a4a541..00000000
--- a/chapter11/03-MinCoinChangeDP.js
+++ /dev/null
@@ -1,38 +0,0 @@
-function MinCoinChange(coins){
-
- var cache = {};
-
- this.makeChange = function(amount) {
- var me = this;
- if (!amount) {
- return [];
- }
- if (cache[amount]) {
- return cache[amount];
- }
- var min = [], newMin, newAmount;
- for (var i=0; i= 0){
- newMin = me.makeChange(newAmount);
- }
- if (
- newAmount >= 0 &&
- (newMin.length < min.length-1 || !min.length) &&
- (newMin.length || !newAmount)
- ){
- min = [coin].concat(newMin);
- console.log('new Min ' + min + ' for ' + amount);
- }
- }
- return (cache[amount] = min);
- };
-}
-
-
-var minCoinChange = new MinCoinChange([1, 5, 10, 25]);
-console.log(minCoinChange.makeChange(36));
-
-var minCoinChange2 = new MinCoinChange([1, 3, 4]);
-console.log(minCoinChange2.makeChange(6));
\ No newline at end of file
diff --git a/chapter11/04-MinCoinChangeGreedy.js b/chapter11/04-MinCoinChangeGreedy.js
deleted file mode 100644
index 3050f7ed..00000000
--- a/chapter11/04-MinCoinChangeGreedy.js
+++ /dev/null
@@ -1,25 +0,0 @@
-function MinCoinChange(coins){
-
- var coins = coins;
-
- var cache = {};
-
- this.makeChange = function(amount) {
- var change = [],
- total = 0;
- for (var i=coins.length; i>=0; i--){
- var coin = coins[i];
- while (total + coin <= amount) {
- change.push(coin);
- total += coin;
- }
- }
- return change;
- };
-}
-
-var minCoinChange = new MinCoinChange([1, 5, 10, 25]);
-console.log(minCoinChange.makeChange(36));
-
-var minCoinChange2 = new MinCoinChange([1, 3, 4]);
-console.log(minCoinChange2.makeChange(6));
\ No newline at end of file
diff --git a/chapter11/05-KnapsackProblemDP.html b/chapter11/05-KnapsackProblemDP.html
deleted file mode 100644
index 316f9722..00000000
--- a/chapter11/05-KnapsackProblemDP.html
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/chapter11/05-KnapsackProblemDP.js b/chapter11/05-KnapsackProblemDP.js
deleted file mode 100644
index fb6adbe7..00000000
--- a/chapter11/05-KnapsackProblemDP.js
+++ /dev/null
@@ -1,53 +0,0 @@
-function knapSack(capacity, weights, values, n) {
-
- var i, w, a, b, kS = [];
-
- for (i = 0; i <= n; i++) {
- kS[i] = [];
- }
-
- for (i = 0; i <= n; i++){
- for (w = 0; w <= capacity; w++){
- if (i == 0 || w == 0){
- kS[i][w] = 0;
-
- } else if (weights[i-1] <= w){
- a = values[i-1] + kS[i-1][w-weights[i-1]];
- b = kS[i-1][w];
- kS[i][w] = (a > b) ? a : b; //max(a,b)
- console.log(a + ' can be part of the solution');
- } else{
- kS[i][w] = kS[i-1][w];
- }
- }
- console.log(kS[i].join());
- }
-
- //extra algorithm to find the items that are part of the solution
- findValues(n, capacity, kS, values, weights);
-
- return kS[n][capacity];
-}
-
-function findValues(n, capacity, kS, weights, values){
- var i=n, k=capacity;
-
- console.log('Items that are part of the solution:');
-
- while (i>0 && k>0){
- if (kS[i][k] !== kS[i-1][k]){
- console.log('item '+i+' can be part of solution w,v: ' + weights[i-1] + ',' + values[i-1]);
- i--;
- k = k - kS[i][k];
- } else {
- i--;
- }
- }
-}
-
-var values = [3,4,5],
- weights = [2,3,4],
- capacity = 5,
- n = values.length;
-
-console.log('Total value that can be carried: ' + knapSack(capacity, weights, values, n));
\ No newline at end of file
diff --git a/chapter11/06-KnapSackProblemRecursive.html b/chapter11/06-KnapSackProblemRecursive.html
deleted file mode 100644
index cc000756..00000000
--- a/chapter11/06-KnapSackProblemRecursive.html
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/chapter11/06-KnapSackProblemRecursive.js b/chapter11/06-KnapSackProblemRecursive.js
deleted file mode 100644
index 583092e1..00000000
--- a/chapter11/06-KnapSackProblemRecursive.js
+++ /dev/null
@@ -1,22 +0,0 @@
-function knapSack(capacity, weights, values, n) {
-
- if (n == 0 || capacity == 0){
- return 0;
- }
-
- if (weights[n-1] > capacity){
- return knapSack(capacity, weights, values, n-1);
-
- } else {
- var a = values[n-1] + knapSack(capacity-weights[n-1], weights, values, n-1),
- b = knapSack(capacity, weights, values, n-1);
- return (a > b) ? a : b;
- }
-}
-
-var values = [3,4,5],
- weights = [2,3,4],
- capacity = 5,
- n = values.length;
-
-console.log(knapSack(capacity, weights, values, n));
\ No newline at end of file
diff --git a/chapter11/07-KnapSackProblemGreedy.html b/chapter11/07-KnapSackProblemGreedy.html
deleted file mode 100644
index 227d7b4b..00000000
--- a/chapter11/07-KnapSackProblemGreedy.html
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/chapter11/07-KnapSackProblemGreedy.js b/chapter11/07-KnapSackProblemGreedy.js
deleted file mode 100644
index 4c12e1a6..00000000
--- a/chapter11/07-KnapSackProblemGreedy.js
+++ /dev/null
@@ -1,28 +0,0 @@
-function knapSack(capacity, values, weights) {
- var n = values.length,
- load = 0,
- i = 0,
- val = 0;
-
- for (i=0; i
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/chapter11/08-LongestCommonSubsequenceDP.js b/chapter11/08-LongestCommonSubsequenceDP.js
deleted file mode 100644
index b5eaf3f1..00000000
--- a/chapter11/08-LongestCommonSubsequenceDP.js
+++ /dev/null
@@ -1,105 +0,0 @@
-function lcs(wordX, wordY) {
-
- var m = wordX.length,
- n = wordY.length,
- l = [],
- i, j, a, b;
-
- for (i = 0; i <= m; ++i) {
- l[i] = [];
- for (j = 0; j <= n; ++j) {
- l[i][j] = 0;
- }
- }
-
- for (i=0; i<=m; i++) {
- for (j=0; j<=n; j++) {
- if (i == 0 || j == 0){
- l[i][j] = 0;
-
- } else if (wordX[i-1] == wordY[j-1]) {
- l[i][j] = l[i-1][j-1] + 1;
-
- } else {
- a = l[i-1][j];
- b = l[i][j-1];
- l[i][j] = (a > b) ? a : b; //max(a,b)
- }
- }
- console.log(l[i].join());
- }
-
- return l[m][n];
-}
-
-//complete algorithm that prints the LCS as well
-
-function lcs2(wordX, wordY) {
-
- var m = wordX.length,
- n = wordY.length,
- l = [],
- solution = [],
- i, j, a, b;
-
- for (i = 0; i <= m; ++i) {
- l[i] = [];
- solution[i] = [];
- for (j = 0; j <= n; ++j) {
- l[i][j] = 0;
- solution[i][j] = '0';
- }
- }
-
- for (i=0; i<=m; i++) {
- for (j=0; j<=n; j++) {
- if (i == 0 || j == 0){
- l[i][j] = 0;
-
- } else if (wordX[i-1] == wordY[j-1]) {
- l[i][j] = l[i-1][j-1] + 1;
- solution[i][j] = 'diagonal';
-
- } else {
- a = l[i-1][j];
- b = l[i][j-1];
- l[i][j] = (a > b) ? a : b; //max(a,b)
-
- solution[i][j] = (l[i][j] == l[i - 1][j]) ? 'top' : 'left';
- }
- }
- console.log(l[i].join());
- console.log(solution[i].join());
- }
-
- printSolution(solution, l, wordX, wordY, m, n);
-
- return l[m][n];
-}
-
-function printSolution(solution, l, wordX, wordY, m, n){
-
- var a = m, b = n, i, j,
- x = solution[a][b],
- answer = '';
-
- while (x !== '0') {
- if (solution[a][b] === 'diagonal') {
- answer = wordX[a - 1] + answer;
- a--;
- b--;
- } else if (solution[a][b] === 'left') {
- b--;
- } else if (solution[a][b] === 'top') {
- a--;
- }
- x = solution[a][b];
- }
-
- console.log('lcs: '+ answer);
-}
-
-var wordX = 'acbaed',
- wordY = 'abcadf';
-
-console.log(lcs2(wordX, wordY));
\ No newline at end of file
diff --git a/chapter11/09-LongestCommonSubsequenceRecursive.html b/chapter11/09-LongestCommonSubsequenceRecursive.html
deleted file mode 100644
index 59573751..00000000
--- a/chapter11/09-LongestCommonSubsequenceRecursive.html
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/chapter11/09-LongestCommonSubsequenceRecursive.js b/chapter11/09-LongestCommonSubsequenceRecursive.js
deleted file mode 100644
index 1c96fab1..00000000
--- a/chapter11/09-LongestCommonSubsequenceRecursive.js
+++ /dev/null
@@ -1,19 +0,0 @@
-function lcs(wordwordX, wordwordY, m, n) {
-
- if (m == 0 || n == 0){
- return 0;
- }
-
- if (wordwordX[m-1] == wordY[n-1]){
- return 1 + lcs(wordX, wordY, m-1, n-1);
- } else {
- var a = lcs(wordX, wordY, m, n-1),
- b = lcs(wordX, wordY, m-1, n);
- return (a > b) ? a : b;
- }
-}
-
-var wordX = 'acbaed',
- wordY = 'abcadf';
-
-console.log(lcs(wordX, wordY, wordX.length, wordY.length));
\ No newline at end of file
diff --git a/chapter11/10-MatrixChainMultiplicationDP.html b/chapter11/10-MatrixChainMultiplicationDP.html
deleted file mode 100644
index 2108a100..00000000
--- a/chapter11/10-MatrixChainMultiplicationDP.html
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/chapter11/10-MatrixChainMultiplicationDP.js b/chapter11/10-MatrixChainMultiplicationDP.js
deleted file mode 100644
index e335b3cc..00000000
--- a/chapter11/10-MatrixChainMultiplicationDP.js
+++ /dev/null
@@ -1,56 +0,0 @@
-function matrixChainOrder(p, n) {
-
- var i, j, k, l, q,
- m = [], s=[];
-
- for (i = 1; i <= n; i++){
- m[i] = [];
- m[i][i] = 0;
-
- }
-
- for (i = 0; i <= n; i++){ //to help printing the optimal solution
- s[i] = []; //auxiliary
- for (j=0; j<=n; j++){
- s[i][j] = 0;
- }
- }
-
- for (l=2; l
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/chapter11/11-MatrixChainMultiplicationRecursive.js b/chapter11/11-MatrixChainMultiplicationRecursive.js
deleted file mode 100644
index 0b327524..00000000
--- a/chapter11/11-MatrixChainMultiplicationRecursive.js
+++ /dev/null
@@ -1,26 +0,0 @@
-function matrixChainOrder(p, i, j){
-
- if(i == j) {
- return 0;
- }
-
- var k, count,
- min = Number.MAX_SAFE_INTEGER;
-
- for (k = i; k
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/chapter11/12-IntroFunctionalProgramming.js b/chapter11/12-IntroFunctionalProgramming.js
deleted file mode 100644
index 47787255..00000000
--- a/chapter11/12-IntroFunctionalProgramming.js
+++ /dev/null
@@ -1,147 +0,0 @@
-console.log('Using imperative JS');
-
-var printArray = function(array){
- for (var i=0; i array[i]){
- minValue = array[i];
- }
- }
-
- return minValue;
-};
-
-console.log(findMinArray([8,6,4,5,9]));
-
-console.log('Finding the min value in an array - functional ES2015');
-const min_ = function(array){
- return Math.min(...array)
-};
-
-//simplifying using arrow functions
-const min = arr => Math.min(...arr);
-
-console.log(min_([8,6,4,5,9]));
-console.log(min([8,6,4,5,9]));
-
-//concat + reduce
-console.log('merge arrays - imperative');
-
-var mergeArrays_ = function(arrays){
- var count = arrays.length,
- newArray = [],
- k =0;
- for (var i=0; i [].concat(...arrays);
-console.log(mergeArrays([1, 2, 3], [4, 5], [6]));
-
-console.log('sum values of arrays - imperative');
-var sumValues = function(array){
- var total = array[0];
- for (var i=1; i arr.reduce((a, b) => a + b);
-
-console.log(sum([1, 2, 3, 4, 5]));
-
-//map
-var daysOfWeek = [
- {name: 'Monday', value: 1},
- {name: 'Tuesday', value: 2},
- {name: 'Wednesday', value: 7}
-];
-
-var daysOfWeekValues_ = [];
-for (var i = 0; i < daysOfWeek.length; i++) {
- daysOfWeekValues_.push(daysOfWeek[i].value);
-}
-
-//to
-var daysOfWeekValues = daysOfWeek.map(function(day) {
- return day.value;
-});
-console.log(daysOfWeekValues);
-
-
-//filter
-var positiveNumbers_ = function(array){
- var positive = [];
- for (var i = 0; i < array.length; i++) {
- if (array[i] >= 0){
- positive.push(array[i]);
- }
- }
- return positive;
-}
-console.log(positiveNumbers_([-1,1,2,-2]));
-
-var positiveNumbers = function(array){
- return array.filter(function(num){
- return num >= 0;
- })
-};
-console.log(positiveNumbers([-1,1,2,-2]));
\ No newline at end of file
diff --git a/chapter12/05-BigONotation.html b/chapter12/05-BigONotation.html
deleted file mode 100644
index 317a5bfb..00000000
--- a/chapter12/05-BigONotation.html
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/chapter12/05-BigONotation.js b/chapter12/05-BigONotation.js
deleted file mode 100644
index a48bd6ab..00000000
--- a/chapter12/05-BigONotation.js
+++ /dev/null
@@ -1,65 +0,0 @@
-//*************** o(1)
-function increment(num){
- console.log('cost for increment with input ' + num + ' is 1');
- return ++num;
-}
-
-increment(1);
-increment(2);
-
-//*************** o(n)
-
-function createNonSortedArray(size){
- var array = [];
-
- for (var i = size; i> 0; i--){
- array[i] = i;
- }
-
- return array;
-}
-
-function sequentialSearch(array, item){
- var cost = 0;
- for (var i=0; i array[j+1]){
- swap(array, j, j+1);
- }
- }
- }
- console.log('cost for bubbleSort with input size ' + length + ' is ' + cost);
-}
-
-var array1 = createNonSortedArray(99);
-var array2 = createNonSortedArray(999);
-var array3 = createNonSortedArray(9999);
-bubbleSort(array1);
-bubbleSort(array2);
-bubbleSort(array3);
\ No newline at end of file
diff --git a/chapter12/bigOChart/chart.js b/chapter12/bigOChart/chart.js
deleted file mode 100644
index 765794df..00000000
--- a/chapter12/bigOChart/chart.js
+++ /dev/null
@@ -1,37 +0,0 @@
-google.load('visualization', '1.0', {'packages':['corechart']});
-google.setOnLoadCallback(drawChart);
-
-function drawChart() {
-
- var data = new google.visualization.DataTable();
- data.addColumn('string', 'n');
- data.addColumn('number', 'O(1)');
- data.addColumn('number', 'O(log n)');
- data.addColumn('number', 'O(n)');
- data.addColumn('number', 'O(n log n)');
- data.addColumn('number', 'O(n^2)');
- data.addColumn('number', 'O(2^n)');
-
- for (var i = 0; i <= 30; i++) {
- data.addRow([i+'', 1, Math.log(i), i, Math.log(i)*i, Math.pow(i,2), Math.pow(2,i)]);
- }
-
- var options = {'title':'Big O Notation Complexity Chart',
- 'width':700,
- 'height':600,
- 'backgroundColor':{stroke:'#CCC',strokeWidth:1},
- 'curveType':'function',
- 'hAxis':{
- title:'Elements (n)',
- showTextEvery:5
- },
- 'vAxis':{
- title:'Operations',
- viewWindowMode:'explicit',
- viewWindow:{min:0,max:450}
- }
- };
-
- var chart = new google.visualization.LineChart(document.getElementById('chart_div'));
- chart.draw(data, options);
-}
\ No newline at end of file
diff --git a/chapter12/bigOChart/index.html b/chapter12/bigOChart/index.html
deleted file mode 100644
index 31118263..00000000
--- a/chapter12/bigOChart/index.html
+++ /dev/null
@@ -1,14 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/examples/PacktDataStructuresAlgorithms.min.js b/examples/PacktDataStructuresAlgorithms.min.js
new file mode 100644
index 00000000..b06c53f5
--- /dev/null
+++ b/examples/PacktDataStructuresAlgorithms.min.js
@@ -0,0 +1 @@
+!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("PacktDataStructuresAlgorithms",[],t):"object"==typeof exports?exports.PacktDataStructuresAlgorithms=t():e.PacktDataStructuresAlgorithms=t()}("undefined"!=typeof self?self:this,function(){return function(e){function t(r){if(n[r])return n[r].exports;var i=n[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,t),i.l=!0,i.exports}var n={};return t.m=e,t.c=n,t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:r})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=14)}([function(e,t,n){var r,i,o;!function(n,u){i=[t],r=u,void 0!==(o="function"==typeof r?r.apply(t,i):r)&&(e.exports=o)}(0,function(e){"use strict";function t(e,t,n){var r=n(e,t);return r===l.LESS_THAN||r===l.EQUALS}function n(e,t,n){var r=n(e,t);return r===l.BIGGER_THAN||r===l.EQUALS}function r(e,t){return e===t?0:e0&&void 0!==arguments[0]?arguments[0]:n.defaultEquals;i(this,e),this.equalsFn=t,this.count=0,this.head=void 0}return o(e,[{key:"push",value:function(e){var t=new r.Node(e),n=void 0;if(null==this.head)this.head=t;else{for(n=this.head;null!=n.next;)n=n.next;n.next=t}this.count++}},{key:"getElementAt",value:function(e){if(e>=0&&e<=this.count){for(var t=this.head,n=0;n=0&&t<=this.count){var n=new r.Node(e);if(0===t){var i=this.head;n.next=i,this.head=n}else{var o=this.getElementAt(t-1);n.next=o.next,o.next=n}return this.count++,!0}return!1}},{key:"removeAt",value:function(e){if(e>=0&&e1&&void 0!==arguments[1]?arguments[1]:t.defaultCompare;if(e&&e.length>0){for(var r=e[0],i=1;i1&&void 0!==arguments[1]?arguments[1]:t.defaultCompare;if(e&&e.length>0){for(var r=e[0],i=1;i0)this.lowestCount--,this.items[this.lowestCount]=e;else{for(var t=this.count;t>0;t--)this.items[t]=this.items[t-1];this.count++,this.items[0]=e}}},{key:"addBack",value:function(e){this.items[this.count]=e,this.count++}},{key:"removeFront",value:function(){if(!this.isEmpty()){var e=this.items[this.lowestCount];return delete this.items[this.lowestCount],this.lowestCount++,e}}},{key:"removeBack",value:function(){if(!this.isEmpty()){this.count--;var e=this.items[this.count];return delete this.items[this.count],e}}},{key:"peekFront",value:function(){if(!this.isEmpty())return this.items[this.lowestCount]}},{key:"peekBack",value:function(){if(!this.isEmpty())return this.items[this.count-1]}},{key:"isEmpty",value:function(){return 0===this.size()}},{key:"clear",value:function(){this.items={},this.count=0,this.lowestCount=0}},{key:"size",value:function(){return this.count-this.lowestCount}},{key:"toString",value:function(){if(this.isEmpty())return"";for(var e=""+this.items[this.lowestCount],t=this.lowestCount+1;t0&&void 0!==arguments[0]?arguments[0]:n.defaultEquals;o(this,t);var r=u(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e));return r.tail=void 0,r}return a(t,e),l(t,[{key:"push",value:function(e){var t=new i.DoublyNode(e);null==this.head?(this.head=t,this.tail=t):(this.tail.next=t,t.prev=this.tail,this.tail=t),this.count++}},{key:"insert",value:function(e,t){if(t>=0&&t<=this.count){var n=new i.DoublyNode(e),r=this.head;if(0===t)null==this.head?(this.head=n,this.tail=n):(n.next=this.head,this.head.prev=n,this.head=n);else if(t===this.count)r=this.tail,r.next=n,n.prev=r,this.tail=n;else{var o=this.getElementAt(t-1);r=o.next,n.next=r,o.next=n,r.prev=n,n.prev=o}return this.count++,!0}return!1}},{key:"removeAt",value:function(e){if(e>=0&&e0&&void 0!==arguments[0]?arguments[0]:n.defaultToString;i(this,e),this.toStrFn=t,this.table={}}return o(e,[{key:"set",value:function(e,t){if(null!=e&&null!=t){var n=this.toStrFn(e);return this.table[n]=new r.ValuePair(e,t),!0}return!1}},{key:"get",value:function(e){var t=this.table[this.toStrFn(e)];return null==t?void 0:t.value}},{key:"hasKey",value:function(e){return null!=this.table[this.toStrFn(e)]}},{key:"remove",value:function(e){return!!this.hasKey(e)&&(delete this.table[this.toStrFn(e)],!0)}},{key:"values",value:function(){return this.keyValues().map(function(e){return e.value})}},{key:"keys",value:function(){return this.keyValues().map(function(e){return e.key})}},{key:"keyValues",value:function(){return Object.values(this.table)}},{key:"forEach",value:function(e){for(var t=this.keyValues(),n=0;n0&&void 0!==arguments[0]?arguments[0]:n.defaultCompare;i(this,e),this.compareFn=t,this.root=null}return o(e,[{key:"insert",value:function(e){null==this.root?this.root=new r.Node(e):this.insertNode(this.root,e)}},{key:"insertNode",value:function(e,t){this.compareFn(t,e.key)===n.Compare.LESS_THAN?null==e.left?e.left=new r.Node(t):this.insertNode(e.left,t):null==e.right?e.right=new r.Node(t):this.insertNode(e.right,t)}},{key:"getRoot",value:function(){return this.root}},{key:"search",value:function(e){return this.searchNode(this.root,e)}},{key:"searchNode",value:function(e,t){return null!=e&&(this.compareFn(t,e.key)===n.Compare.LESS_THAN?this.searchNode(e.left,t):this.compareFn(t,e.key)!==n.Compare.BIGGER_THAN||this.searchNode(e.right,t))}},{key:"inOrderTraverse",value:function(e){this.inOrderTraverseNode(this.root,e)}},{key:"inOrderTraverseNode",value:function(e,t){null!=e&&(this.inOrderTraverseNode(e.left,t),t(e.key),this.inOrderTraverseNode(e.right,t))}},{key:"preOrderTraverse",value:function(e){this.preOrderTraverseNode(this.root,e)}},{key:"preOrderTraverseNode",value:function(e,t){null!=e&&(t(e.key),this.preOrderTraverseNode(e.left,t),this.preOrderTraverseNode(e.right,t))}},{key:"postOrderTraverse",value:function(e){this.postOrderTraverseNode(this.root,e)}},{key:"postOrderTraverseNode",value:function(e,t){null!=e&&(this.postOrderTraverseNode(e.left,t),this.postOrderTraverseNode(e.right,t),t(e.key))}},{key:"min",value:function(){return this.minNode(this.root)}},{key:"minNode",value:function(e){for(var t=e;null!=t&&null!=t.left;)t=t.left;return t}},{key:"max",value:function(){return this.maxNode(this.root)}},{key:"maxNode",value:function(e){for(var t=e;null!=t&&null!=t.right;)t=t.right;return t}},{key:"remove",value:function(e){this.root=this.removeNode(this.root,e)}},{key:"removeNode",value:function(e,t){if(null==e)return null;if(this.compareFn(t,e.key)===n.Compare.LESS_THAN)return e.left=this.removeNode(e.left,t),e;if(this.compareFn(t,e.key)===n.Compare.BIGGER_THAN)return e.right=this.removeNode(e.right,t),e;if(null==e.left&&null==e.right)return e=null;if(null==e.left)return e=e.right;if(null==e.right)return e=e.left;var r=this.minNode(e.right);return e.key=r.key,e.right=this.removeNode(e.right,r.key),e}}]),e}();t.default=u,e.exports=t.default})},function(e,t,n){var r,i,o;!function(n,u){i=[t],r=u,void 0!==(o="function"==typeof r?r.apply(t,i):r)&&(e.exports=o)}(0,function(e){"use strict";function t(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(e,"__esModule",{value:!0});var n=function(){function e(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:t.defaultCompare,r=e.length,i=void 0,o=1;o0&&n(e[u-1],i)===t.Compare.BIGGER_THAN;)e[u]=e[u-1],u--;e[u]=i}return e}})},function(e,t,n){var r,i,o;!function(u,a){i=[t,n(0)],r=a,void 0!==(o="function"==typeof r?r.apply(t,i):r)&&(e.exports=o)}(0,function(e,t){"use strict";function n(e,n,r,i){for(var o=e[Math.floor((r+n)/2)],u=n,a=r;u<=a;){for(;i(e[u],o)===t.Compare.LESS_THAN;)u++;for(;i(e[a],o)===t.Compare.BIGGER_THAN;)a--;u<=a&&((0,t.swap)(e,u,a),u++,a--)}return u}function r(e,t,i,o){var u=void 0;return e.length>1&&(u=n(e,t,i,o),t1&&void 0!==arguments[1]?arguments[1]:t.defaultCompare;return r(e,0,e.length-1,n)}Object.defineProperty(e,"__esModule",{value:!0}),e.quickSort=i})},function(e,t,n){var r,i,o;!function(u,a){i=[t,n(15),n(3),n(16),n(17),n(18),n(4),n(7),n(19),n(20),n(1),n(8),n(21),n(22),n(23),n(24),n(9),n(25),n(26),n(27),n(28),n(30),n(31),n(10),n(32),n(53),n(33),n(34),n(35),n(36),n(37),n(38),n(39),n(40),n(41),n(42),n(43),n(44),n(45),n(12),n(46),n(13),n(47),n(48),n(49),n(50),n(51),n(52),n(6),n(0)],r=a,void 0!==(o="function"==typeof r?r.apply(t,i):r)&&(e.exports=o)}(0,function(e,t,n,r,i,o,u,a,f,l,s,c,h,p,v,d,y,b,g,m,k,_,O,E,S,j,P,w,x,C,T,N,L,A,M,H,F,B,I,D,R,G,z,q,V,U,Y,W,K,X){"use strict";function Q(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(e,"__esModule",{value:!0}),e.findMinValue=e.findMaxValue=e.sequentialSearch=e.interpolationSearch=e.binarySearch=e.shellSort=e.selectionSort=e.radixSort=e.quickSort=e.mergeSort=e.insertionSort=e.countingSort=e.bucketSort=e.modifiedBubbleSort=e.bubbleSort=e.shuffle=e.kruskal=e.prim=e.floydWarshall=e.dijkstra=e.DFS=e.depthFirstSearch=e.BFS=e.breadthFirstSearch=e.Graph=e.heapSort=e.MaxHeap=e.MinHeap=e.AVLTree=e.BinarySearchTree=e.fibonacciMemoization=e.fibonacciIterative=e.fibonacci=e.factorial=e.factorialIterative=e.HashTableLinearProbingLazy=e.HashTableLinearProbing=e.HashTableSeparateChaining=e.HashTable=e.Dictionary=e.Set=e.StackLinkedList=e.SortedLinkedList=e.CircularLinkedList=e.DoublyLinkedList=e.LinkedList=e.palindromeChecker=e.hotPotato=e.Deque=e.Queue=e.parenthesesChecker=e.decimalToBinary=e.baseConverter=e.hanoiStack=e.hanoi=e.Stack=e.StackArray=e.util=void 0,Object.defineProperty(e,"StackArray",{enumerable:!0,get:function(){return Q(t).default}}),Object.defineProperty(e,"Stack",{enumerable:!0,get:function(){return Q(n).default}}),Object.defineProperty(e,"hanoi",{enumerable:!0,get:function(){return Q(r).default}}),Object.defineProperty(e,"hanoiStack",{enumerable:!0,get:function(){return Q(r).default}}),Object.defineProperty(e,"baseConverter",{enumerable:!0,get:function(){return Q(i).default}}),Object.defineProperty(e,"decimalToBinary",{enumerable:!0,get:function(){return Q(i).default}}),Object.defineProperty(e,"parenthesesChecker",{enumerable:!0,get:function(){return Q(o).default}}),Object.defineProperty(e,"Queue",{enumerable:!0,get:function(){return Q(u).default}}),Object.defineProperty(e,"Deque",{enumerable:!0,get:function(){return Q(a).default}}),Object.defineProperty(e,"hotPotato",{enumerable:!0,get:function(){return Q(f).default}}),Object.defineProperty(e,"palindromeChecker",{enumerable:!0,get:function(){return Q(l).default}}),Object.defineProperty(e,"LinkedList",{enumerable:!0,get:function(){return Q(s).default}}),Object.defineProperty(e,"DoublyLinkedList",{enumerable:!0,get:function(){return Q(c).default}}),Object.defineProperty(e,"CircularLinkedList",{enumerable:!0,get:function(){return Q(h).default}}),Object.defineProperty(e,"SortedLinkedList",{enumerable:!0,get:function(){return Q(p).default}}),Object.defineProperty(e,"StackLinkedList",{enumerable:!0,get:function(){return Q(v).default}}),Object.defineProperty(e,"Set",{enumerable:!0,get:function(){return Q(d).default}}),Object.defineProperty(e,"Dictionary",{enumerable:!0,get:function(){return Q(y).default}}),Object.defineProperty(e,"HashTable",{enumerable:!0,get:function(){return Q(b).default}}),Object.defineProperty(e,"HashTableSeparateChaining",{enumerable:!0,get:function(){return Q(g).default}}),Object.defineProperty(e,"HashTableLinearProbing",{enumerable:!0,get:function(){return Q(m).default}}),Object.defineProperty(e,"HashTableLinearProbingLazy",{enumerable:!0,get:function(){return Q(k).default}}),Object.defineProperty(e,"factorialIterative",{enumerable:!0,get:function(){return Q(_).default}}),Object.defineProperty(e,"factorial",{enumerable:!0,get:function(){return Q(_).default}}),Object.defineProperty(e,"fibonacci",{enumerable:!0,get:function(){return Q(O).default}}),Object.defineProperty(e,"fibonacciIterative",{enumerable:!0,get:function(){return Q(O).default}}),Object.defineProperty(e,"fibonacciMemoization",{enumerable:!0,get:function(){return Q(O).default}}),Object.defineProperty(e,"BinarySearchTree",{enumerable:!0,get:function(){return Q(E).default}}),Object.defineProperty(e,"AVLTree",{enumerable:!0,get:function(){return Q(S).default}}),Object.defineProperty(e,"MinHeap",{enumerable:!0,get:function(){return j.MinHeap}}),Object.defineProperty(e,"MaxHeap",{enumerable:!0,get:function(){return j.MaxHeap}}),Object.defineProperty(e,"heapSort",{enumerable:!0,get:function(){return Q(P).default}}),Object.defineProperty(e,"Graph",{enumerable:!0,get:function(){return Q(w).default}}),Object.defineProperty(e,"breadthFirstSearch",{enumerable:!0,get:function(){return x.breadthFirstSearch}}),Object.defineProperty(e,"BFS",{enumerable:!0,get:function(){return x.BFS}}),Object.defineProperty(e,"depthFirstSearch",{enumerable:!0,get:function(){return C.depthFirstSearch}}),Object.defineProperty(e,"DFS",{enumerable:!0,get:function(){return C.DFS}}),Object.defineProperty(e,"dijkstra",{enumerable:!0,get:function(){return T.dijkstra}}),Object.defineProperty(e,"floydWarshall",{enumerable:!0,get:function(){return N.floydWarshall}}),Object.defineProperty(e,"prim",{enumerable:!0,get:function(){return L.prim}}),Object.defineProperty(e,"kruskal",{enumerable:!0,get:function(){return A.kruskal}}),Object.defineProperty(e,"shuffle",{enumerable:!0,get:function(){return M.shuffle}}),Object.defineProperty(e,"bubbleSort",{enumerable:!0,get:function(){return H.bubbleSort}}),Object.defineProperty(e,"modifiedBubbleSort",{enumerable:!0,get:function(){return F.modifiedBubbleSort}}),Object.defineProperty(e,"bucketSort",{enumerable:!0,get:function(){return B.bucketSort}}),Object.defineProperty(e,"countingSort",{enumerable:!0,get:function(){return I.countingSort}}),Object.defineProperty(e,"insertionSort",{enumerable:!0,get:function(){return D.insertionSort}}),Object.defineProperty(e,"mergeSort",{enumerable:!0,get:function(){return R.mergeSort}}),Object.defineProperty(e,"quickSort",{enumerable:!0,get:function(){return G.quickSort}}),Object.defineProperty(e,"radixSort",{enumerable:!0,get:function(){return z.radixSort}}),Object.defineProperty(e,"selectionSort",{enumerable:!0,get:function(){return q.selectionSort}}),Object.defineProperty(e,"shellSort",{enumerable:!0,get:function(){return V.shellSort}}),Object.defineProperty(e,"binarySearch",{enumerable:!0,get:function(){return U.binarySearch}}),Object.defineProperty(e,"interpolationSearch",{enumerable:!0,get:function(){return Y.interpolationSearch}}),Object.defineProperty(e,"sequentialSearch",{enumerable:!0,get:function(){return W.sequentialSearch}}),Object.defineProperty(e,"findMaxValue",{enumerable:!0,get:function(){return K.findMaxValue}}),Object.defineProperty(e,"findMinValue",{enumerable:!0,get:function(){return K.findMinValue}});var J=function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t.default=e,t}(X);e.util=J})},function(e,t,n){var r,i,o;!function(n,u){i=[e,t],r=u,void 0!==(o="function"==typeof r?r.apply(t,i):r)&&(e.exports=o)}(0,function(e,t){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var r=function(){function e(e,t){for(var n=0;n7&&void 0!==arguments[7]?arguments[7]:[];if(e<=0)return f;if(1===e){i.push(t.pop());var l={};l[o]=t.toString(),l[u]=r.toString(),l[a]=i.toString(),f.push(l)}else{n(e-1,t,i,r,o,a,u,f),i.push(t.pop());var s={};s[o]=t.toString(),s[u]=r.toString(),s[a]=i.toString(),f.push(s),n(e-1,r,t,i,u,o,a,f)}return f}function r(e){for(var t=new o.default,r=new o.default,i=new o.default,u=e;u>0;u--)t.push(u);return n(e,t,i,r,"source","helper","dest")}function i(e,t,n,r){var o=arguments.length>4&&void 0!==arguments[4]?arguments[4]:[];return e<=0?o:(1===e?o.push([t,r]):(i(e-1,t,r,n,o),o.push([t,r]),i(e-1,n,t,r,o)),o)}Object.defineProperty(e,"__esModule",{value:!0}),e.hanoiStack=r,e.hanoi=i;var o=function(e){return e&&e.__esModule?e:{default:e}}(t)})},function(e,t,n){var r,i,o;!function(u,a){i=[t,n(3)],r=a,void 0!==(o="function"==typeof r?r.apply(t,i):r)&&(e.exports=o)}(0,function(e,t){"use strict";function n(e){for(var t=new i.default,n=e,r=void 0,o="";n>0;)r=Math.floor(n%2),t.push(r),n=Math.floor(n/2);for(;!t.isEmpty();)o+=t.pop().toString();return o}function r(e,t){var n=new i.default,r=e,o=void 0,u="";if(!(t>=2&&t<=36))return"";for(;r>0;)o=Math.floor(r%t),n.push(o),r=Math.floor(r/t);for(;!n.isEmpty();)u+="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"[n.pop()];return u}Object.defineProperty(e,"__esModule",{value:!0}),e.decimalToBinary=n,e.baseConverter=r;var i=function(e){return e&&e.__esModule?e:{default:e}}(t)})},function(e,t,n){var r,i,o;!function(u,a){i=[t,n(3)],r=a,void 0!==(o="function"==typeof r?r.apply(t,i):r)&&(e.exports=o)}(0,function(e,t){"use strict";function n(e){for(var t=new r.default,n="([{",i=")]}",o=!0,u=0,a=void 0,f=void 0;u=0?t.push(a):t.isEmpty()?o=!1:(f=t.pop(),n.indexOf(f)!==i.indexOf(a)&&(o=!1)),u++;return!(!o||!t.isEmpty())}Object.defineProperty(e,"__esModule",{value:!0}),e.parenthesesChecker=n;var r=function(e){return e&&e.__esModule?e:{default:e}}(t)})},function(e,t,n){var r,i,o;!function(u,a){i=[t,n(4)],r=a,void 0!==(o="function"==typeof r?r.apply(t,i):r)&&(e.exports=o)}(0,function(e,t){"use strict";function n(e,t){for(var n=new r.default,i=[],o=0;o1;){for(var u=0;u1&&i;)o=t.removeFront(),u=t.removeBack(),o!==u&&(i=!1);return i}Object.defineProperty(e,"__esModule",{value:!0}),e.palindromeChecker=n;var r=function(e){return e&&e.__esModule?e:{default:e}}(t)})},function(e,t,n){var r,i,o;!function(u,a){i=[e,t,n(0),n(1),n(5)],r=a,void 0!==(o="function"==typeof r?r.apply(t,i):r)&&(e.exports=o)}(0,function(e,t,n,r,i){"use strict";function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function u(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function a(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}Object.defineProperty(t,"__esModule",{value:!0});var f=function(e){return e&&e.__esModule?e:{default:e}}(r),l=function(){function e(e,t){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:n.defaultEquals;return o(this,t),u(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e))}return a(t,e),l(t,[{key:"push",value:function(e){var t=new i.Node(e),n=void 0;null==this.head?this.head=t:(n=this.getElementAt(this.size()-1),n.next=t),t.next=this.head,this.count++}},{key:"insert",value:function(e,t){if(t>=0&&t<=this.count){var n=new i.Node(e),r=this.head;if(0===t)null==this.head?(this.head=n,n.next=this.head):(n.next=r,r=this.getElementAt(this.size()),this.head=n,r.next=this.head);else{var o=this.getElementAt(t-1);n.next=o.next,o.next=n}return this.count++,!0}return!1}},{key:"removeAt",value:function(e){if(e>=0&&e0&&void 0!==arguments[0]?arguments[0]:n.defaultEquals,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:n.defaultCompare;i(this,t);var u=o(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e));return u.equalsFn=e,u.compareFn=r,u}return u(t,e),f(t,[{key:"push",value:function(e){if(this.isEmpty())l(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),"push",this).call(this,e);else{var n=this.getIndexNextSortedElement(e);l(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),"insert",this).call(this,e,n)}}},{key:"insert",value:function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;if(this.isEmpty())return l(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),"insert",this).call(this,e,0===n?n:0);var r=this.getIndexNextSortedElement(e);return l(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),"insert",this).call(this,e,r)}},{key:"getIndexNextSortedElement",value:function(e){for(var t=this.head,r=0;r0&&(o=i,u=r),u.forEach(function(e){o.includes(e)&&n.add(e)}),n}},{key:"difference",value:function(t){var n=new e;return this.values().forEach(function(e){t.has(e)||n.add(e)}),n}},{key:"isSubsetOf",value:function(e){if(this.size()>e.size())return!1;var t=!0;return this.values().every(function(n){return!!e.has(n)||(t=!1,!1)}),t}},{key:"isEmpty",value:function(){return 0===this.size()}},{key:"size",value:function(){return Object.keys(this.items).length}},{key:"clear",value:function(){this.items={}}},{key:"toString",value:function(){if(this.isEmpty())return"";for(var e=this.values(),t=""+e[0],n=1;n0&&void 0!==arguments[0]?arguments[0]:n.defaultToString;i(this,e),this.toStrFn=t,this.table={}}return o(e,[{key:"loseloseHashCode",value:function(e){if("number"==typeof e)return e;for(var t=this.toStrFn(e),n=0,r=0;r "+this.table[e[0]].toString()+"}",n=1;n "+this.table[e[n]].toString()+"}";return t}}]),e}();t.default=u,e.exports=t.default})},function(e,t,n){var r,i,o;!function(u,a){i=[e,t,n(0),n(1),n(2)],r=a,void 0!==(o="function"==typeof r?r.apply(t,i):r)&&(e.exports=o)}(0,function(e,t,n,r,i){"use strict";function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var u=function(e){return e&&e.__esModule?e:{default:e}}(r),a=function(){function e(e,t){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:n.defaultToString;o(this,e),this.toStrFn=t,this.table={}}return a(e,[{key:"loseloseHashCode",value:function(e){if("number"==typeof e)return e;for(var t=this.toStrFn(e),n=0,r=0;r "+this.table[e[0]].toString()+"}",n=1;n "+this.table[e[n]].toString()+"}";return t}}]),e}();t.default=f,e.exports=t.default})},function(e,t,n){var r,i,o;!function(u,a){i=[e,t,n(0),n(2)],r=a,void 0!==(o="function"==typeof r?r.apply(t,i):r)&&(e.exports=o)}(0,function(e,t,n,r){"use strict";function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var o=function(){function e(e,t){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:n.defaultToString;i(this,e),this.toStrFn=t,this.table={}}return o(e,[{key:"loseloseHashCode",value:function(e){if("number"==typeof e)return e;for(var t=this.toStrFn(e),n=0,r=0;r "+this.table[e[0]].toString()+"}",n=1;n "+this.table[e[n]].toString()+"}";return t}}]),e}();t.default=u,e.exports=t.default})},function(e,t,n){var r,i,o;!function(u,a){i=[e,t,n(0),n(29)],r=a,void 0!==(o="function"==typeof r?r.apply(t,i):r)&&(e.exports=o)}(0,function(e,t,n,r){"use strict";function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var o=function(){function e(e,t){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:n.defaultToString;i(this,e),this.toStrFn=t,this.table={}}return o(e,[{key:"loseloseHashCode",value:function(e){if("number"==typeof e)return e;for(var t=this.toStrFn(e),n=0,r=0;r "+this.table[e[0]].toString()+"}",n=1;n "+this.table[e[n]].toString()+"}";return t}}]),e}();t.default=u,e.exports=t.default})},function(e,t,n){var r,i,o;!function(u,a){i=[t,n(2)],r=a,void 0!==(o="function"==typeof r?r.apply(t,i):r)&&(e.exports=o)}(0,function(e,t){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function r(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function i(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}Object.defineProperty(e,"__esModule",{value:!0}),e.ValuePairLazy=void 0;e.ValuePairLazy=function(e){function t(e,i){var o=arguments.length>2&&void 0!==arguments[2]&&arguments[2];n(this,t);var u=r(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e,i));return u.key=e,u.value=i,u.isDeleted=o,u}return i(t,e),t}(t.ValuePair)})},function(e,t,n){var r,i,o;!function(n,u){i=[t],r=u,void 0!==(o="function"==typeof r?r.apply(t,i):r)&&(e.exports=o)}(0,function(e){"use strict";function t(e){if(!(e<0)){for(var t=1,n=e;n>1;n--)t*=n;return t}}function n(e){if(!(e<0))return 1===e||0===e?1:e*n(e-1)}Object.defineProperty(e,"__esModule",{value:!0}),e.factorialIterative=t,e.factorial=n})},function(e,t,n){var r,i,o;!function(n,u){i=[t],r=u,void 0!==(o="function"==typeof r?r.apply(t,i):r)&&(e.exports=o)}(0,function(e){"use strict";function t(e){return e<1?0:e<=2?1:t(e-1)+t(e-2)}function n(e){if(e<1)return 0;for(var t=0,n=1,r=e,i=2;i<=e;i++)r=n+t,t=n,n=r;return r}function r(e){if(e<1)return 0;var t=[0,1];return function e(n){return null!=t[n]?t[n]:(t[n]=e(n-1)+e(n-2),t[n]=e(n-1)+e(n-2))}(e)}Object.defineProperty(e,"__esModule",{value:!0}),e.fibonacci=t,e.fibonacciIterative=n,e.fibonacciMemoization=r})},function(e,t,n){var r,i,o;!function(u,a){i=[e,t,n(0),n(10),n(11)],r=a,void 0!==(o="function"==typeof r?r.apply(t,i):r)&&(e.exports=o)}(0,function(e,t,n,r,i){"use strict";function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function u(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function a(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}Object.defineProperty(t,"__esModule",{value:!0});var f=function(e){return e&&e.__esModule?e:{default:e}}(r),l=function(){function e(e,t){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:n.defaultCompare;o(this,t);var r=u(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e));return r.compareFn=e,r.root=null,r}return a(t,e),l(t,[{key:"getNodeHeight",value:function(e){return null==e?-1:Math.max(this.getNodeHeight(e.left),this.getNodeHeight(e.right))+1}},{key:"rotationLL",value:function(e){var t=e.left;return e.left=t.right,t.right=e,t}},{key:"rotationRR",value:function(e){var t=e.right;return e.right=t.left,t.left=e,t}},{key:"rotationLR",value:function(e){return e.left=this.rotationRR(e.left),this.rotationLL(e)}},{key:"rotationRL",value:function(e){return e.right=this.rotationLL(e.right),this.rotationRR(e)}},{key:"getBalanceFactor",value:function(e){switch(this.getNodeHeight(e.left)-this.getNodeHeight(e.right)){case-2:return c.UNBALANCED_RIGHT;case-1:return c.SLIGHTLY_UNBALANCED_RIGHT;case 1:return c.SLIGHTLY_UNBALANCED_LEFT;case 2:return c.UNBALANCED_LEFT;default:return c.BALANCED}}},{key:"insert",value:function(e){this.root=this.insertNode(this.root,e)}},{key:"insertNode",value:function(e,t){if(null==e)return new i.Node(t);if(this.compareFn(t,e.key)===n.Compare.LESS_THAN)e.left=this.insertNode(e.left,t);else{if(this.compareFn(t,e.key)!==n.Compare.BIGGER_THAN)return e;e.right=this.insertNode(e.right,t)}var r=this.getBalanceFactor(e);if(r===c.UNBALANCED_LEFT){if(this.compareFn(t,e.left.key)!==n.Compare.LESS_THAN)return this.rotationLR(e);e=this.rotationLL(e)}if(r===c.UNBALANCED_RIGHT){if(this.compareFn(t,e.right.key)!==n.Compare.BIGGER_THAN)return this.rotationRL(e);e=this.rotationRR(e)}return e}},{key:"removeNode",value:function(e,n){if(null==(e=s(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),"removeNode",this).call(this,e,n)))return e;var r=this.getBalanceFactor(e);if(r===c.UNBALANCED_LEFT){if(this.getBalanceFactor(e.left)===c.BALANCED||this.getBalanceFactor(e.left)===c.SLIGHTLY_UNBALANCED_LEFT)return this.rotationLL(e);if(this.getBalanceFactor(e.left)===c.SLIGHTLY_UNBALANCED_RIGHT)return this.rotationLR(e.left)}if(r===c.UNBALANCED_RIGHT){if(this.getBalanceFactor(e.right)===c.BALANCED||this.getBalanceFactor(e.right)===c.SLIGHTLY_UNBALANCED_RIGHT)return this.rotationRR(e);if(this.getBalanceFactor(e.right)===c.SLIGHTLY_UNBALANCED_LEFT)return this.rotationRL(e.right)}return e}}]),t}(f.default);t.default=h,e.exports=t.default})},function(e,t,n){var r,i,o;!function(u,a){i=[e,t,n(0)],r=a,void 0!==(o="function"==typeof r?r.apply(t,i):r)&&(e.exports=o)}(0,function(e,t,n){"use strict";function r(e,t,i,o){var u=t,a=2*t+1,f=2*t+2;a0&&(u=a),f0&&(u=f),u!==t&&((0,n.swap)(e,t,u),r(e,u,i,o))}function i(e,t){for(var n=Math.floor(e.length/2);n>=0;n-=1)r(e,n,e.length,t);return e}function o(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:n.defaultCompare,o=e.length;for(i(e,t);o>1;)(0,n.swap)(e,0,--o),r(e,0,o,t);return e}Object.defineProperty(t,"__esModule",{value:!0}),t.default=o,e.exports=t.default})},function(e,t,n){var r,i,o;!function(u,a){i=[e,t,n(9)],r=a,void 0!==(o="function"==typeof r?r.apply(t,i):r)&&(e.exports=o)}(0,function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var i=function(e){return e&&e.__esModule?e:{default:e}}(n),o=function(){function e(e,t){for(var n=0;n0&&void 0!==arguments[0]&&arguments[0];r(this,e),this.isDirected=t,this.vertices=[],this.adjList=new i.default}return o(e,[{key:"addVertex",value:function(e){this.vertices.includes(e)||(this.vertices.push(e),this.adjList.set(e,[]))}},{key:"addEdge",value:function(e,t){this.adjList.get(e)||this.addVertex(e),this.adjList.get(t)||this.addVertex(t),this.adjList.get(e).push(t),this.isDirected||this.adjList.get(t).push(e)}},{key:"getVertices",value:function(){return this.vertices}},{key:"getAdjList",value:function(){return this.adjList}},{key:"toString",value:function(){for(var e="",t=0;t ";for(var n=this.adjList.get(this.vertices[t]),r=0;r1&&void 0!==arguments[1]?arguments[1]:t.defaultCompare,r=e.length,i=0;i1&&void 0!==arguments[1]?arguments[1]:t.defaultCompare,r=e.length,i=0;ir&&(r=e[i]);for(var o=Math.floor((r-n)/t)+1,u=[],a=0;a1&&void 0!==arguments[1]?arguments[1]:5;return e.length<2?e:i(r(e,t))}Object.defineProperty(e,"__esModule",{value:!0}),e.bucketSort=o})},function(e,t,n){var r,i,o;!function(u,a){i=[t,n(6)],r=a,void 0!==(o="function"==typeof r?r.apply(t,i):r)&&(e.exports=o)}(0,function(e,t){"use strict";function n(e){if(e.length<2)return e;var n=(0,t.findMaxValue)(e),r=0,i=new Array(n+1);return e.forEach(function(e){i[e]||(i[e]=0),i[e]++}),i.forEach(function(t,n){for(;t>0;)e[r++]=n,t--}),e}Object.defineProperty(e,"__esModule",{value:!0}),e.countingSort=n})},function(e,t,n){var r,i,o;!function(u,a){i=[t,n(0)],r=a,void 0!==(o="function"==typeof r?r.apply(t,i):r)&&(e.exports=o)}(0,function(e,t){"use strict";function n(e,n,r){for(var i=0,o=0,u=[];i1&&void 0!==arguments[1]?arguments[1]:t.defaultCompare;if(e.length>1){var o=e,u=o.length,a=Math.floor(u/2);e=n(r(e.slice(0,a),i),r(e.slice(a,u),i),i)}return e}Object.defineProperty(e,"__esModule",{value:!0}),e.mergeSort=r})},function(e,t,n){var r,i,o;!function(u,a){i=[t,n(6)],r=a,void 0!==(o="function"==typeof r?r.apply(t,i):r)&&(e.exports=o)}(0,function(e,t){"use strict";function n(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:10;if(e.length<2)return e;for(var r=(0,t.findMinValue)(e),o=(0,t.findMaxValue)(e),u=1;(o-r)/u>=1;)e=i(e,n,u,r),u*=n;return e}Object.defineProperty(e,"__esModule",{value:!0}),e.radixSort=n;var r=function(e,t,n,r){return Math.floor((e-t)/n%r)},i=function(e,t,n,i){for(var o=void 0,u=[],a=[],f=0;f=0;c--)o=r(e[c],i,n,t),a[--u[o]]=e[c];for(var h=0;h1&&void 0!==arguments[1]?arguments[1]:t.defaultCompare,r=e.length,i=void 0,o=0;o1&&void 0!==arguments[1]?arguments[1]:t.defaultCompare,r=e.length/2;r>0;){for(var i=r;i=r&&n(e[o-r],u)===t.Compare.BIGGER_THAN;)e[o]=e[o-r],o-=r;e[o]=u}r=2===r?1:Math.floor(5*r/11)}return e}Object.defineProperty(e,"__esModule",{value:!0}),e.shellSort=n})},function(e,t,n){var r,i,o;!function(u,a){i=[t,n(0),n(13)],r=a,void 0!==(o="function"==typeof r?r.apply(t,i):r)&&(e.exports=o)}(0,function(e,t,n){"use strict";function r(e,r){for(var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t.defaultCompare,o=(0,n.quickSort)(e),u=0,a=o.length-1;u<=a;){var f=Math.floor((u+a)/2),l=o[f];if(i(l,r)===t.Compare.LESS_THAN)u=f+1;else{if(i(l,r)!==t.Compare.BIGGER_THAN)return f;a=f-1}}return t.DOES_NOT_EXIST}Object.defineProperty(e,"__esModule",{value:!0}),e.binarySearch=r})},function(e,t,n){var r,i,o;!function(u,a){i=[t,n(0)],r=a,void 0!==(o="function"==typeof r?r.apply(t,i):r)&&(e.exports=o)}(0,function(e,t){"use strict";function n(e,n){for(var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t.defaultCompare,i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:t.defaultEquals,o=arguments.length>4&&void 0!==arguments[4]?arguments[4]:t.defaultDiff,u=e.length,a=0,f=u-1,l=-1,s=-1;a<=f&&(0,t.biggerEquals)(n,e[a],r)&&(0,t.lesserEquals)(n,e[f],r);){if(s=o(n,e[a])/o(e[f],e[a]),l=a+Math.floor((f-a)*s),i(e[l],n))return l;r(e[l],n)===t.Compare.LESS_THAN?a=l+1:f=l-1}return t.DOES_NOT_EXIST}Object.defineProperty(e,"__esModule",{value:!0}),e.interpolationSearch=n})},function(e,t,n){var r,i,o;!function(u,a){i=[t,n(0)],r=a,void 0!==(o="function"==typeof r?r.apply(t,i):r)&&(e.exports=o)}(0,function(e,t){"use strict";function n(e,n){for(var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t.defaultEquals,i=0;i0&&void 0!==arguments[0]?arguments[0]:t.defaultCompare;i(this,e),this.compareFn=n,this.heap=[]}return o(e,[{key:"getLeftIndex",value:function(e){return 2*e+1}},{key:"getRightIndex",value:function(e){return 2*e+2}},{key:"getParentIndex",value:function(e){if(0!==e)return Math.floor((e-1)/2)}},{key:"size",value:function(){return this.heap.length}},{key:"isEmpty",value:function(){return this.size()<=0}},{key:"clear",value:function(){this.heap=[]}},{key:"find",value:function(){return this.isEmpty()?void 0:this.heap[0]}},{key:"insert",value:function(e){if(null!=e){var t=this.heap.length;return this.heap.push(e),this.siftUp(t),!0}return!1}},{key:"siftDown",value:function(e){var n=e,r=this.getLeftIndex(e),i=this.getRightIndex(e),o=this.size();rt.Compare.BIGGER_THAN&&(n=r),it.Compare.BIGGER_THAN&&(n=i),e!==n&&((0,t.swap)(this.heap,e,n),this.siftDown(n))}},{key:"siftUp",value:function(e){for(var n=this.getParentIndex(e);e>0&&this.compareFn(this.heap[n],this.heap[e])>t.Compare.BIGGER_THAN;)(0,t.swap)(this.heap,n,e),e=n,n=this.getParentIndex(e)}},{key:"extract",value:function(){if(!this.isEmpty()){if(1===this.size())return this.heap.shift();var e=this.heap.shift();return this.siftDown(0),e}}},{key:"heapify",value:function(e){e&&(this.heap=e,this.heap.unshift(null));for(var t=this.size()-1;t>0;t--)this.siftDown(t)}}]),e}();e.MaxHeap=function(e){function o(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:t.defaultCompare;i(this,o);var r=n(this,(o.__proto__||Object.getPrototypeOf(o)).call(this,e));return r.compareFn=e,r.compareFn=(0,t.reverseCompare)(e),r}return r(o,e),o}(u)})}])});
\ No newline at end of file
diff --git a/chapter01/01-HelloWorld.html b/examples/chapter01/01-HelloWorld.html
similarity index 100%
rename from chapter01/01-HelloWorld.html
rename to examples/chapter01/01-HelloWorld.html
diff --git a/examples/chapter01/01-HelloWorld.js b/examples/chapter01/01-HelloWorld.js
new file mode 100644
index 00000000..b67b0e2c
--- /dev/null
+++ b/examples/chapter01/01-HelloWorld.js
@@ -0,0 +1,10 @@
+// @ts-check
+/* eslint-disable */
+
+function output(t) {
+ document.write('' + t + '
');
+}
+
+alert('Hello, World!');
+console.log('Hello, World!');
+output('Hello, World!');
diff --git a/chapter01/02-Variables.html b/examples/chapter01/02-Variables.html
similarity index 100%
rename from chapter01/02-Variables.html
rename to examples/chapter01/02-Variables.html
diff --git a/examples/chapter01/02-Variables.js b/examples/chapter01/02-Variables.js
new file mode 100644
index 00000000..4d1cf7d5
--- /dev/null
+++ b/examples/chapter01/02-Variables.js
@@ -0,0 +1,40 @@
+// @ts-check
+/* eslint-disable */
+
+var num = 1; // {1}
+num = 3; // {2}
+
+var price = 1.5; // {3}
+var myName = 'Packt'; // {4}
+var trueValue = true; // {5}
+var nullVar = null; // {6}
+var und; // {7}
+
+console.log('num: ' + num);
+console.log('myName: ' + myName);
+console.log('trueValue: ' + trueValue);
+console.log('price: ' + price);
+console.log('nullVar: ' + nullVar);
+console.log('und: ' + und);
+
+// ******* Variable Scope
+
+var myVariable = 'global';
+myOtherVariable = 'global';
+
+function myFunction() {
+ var myVariable = 'local';
+ return myVariable;
+}
+
+function myOtherFunction() {
+ myOtherVariable = 'local';
+ return myOtherVariable;
+}
+
+console.log(myVariable); //{1}
+console.log(myFunction()); //{2}
+
+console.log(myOtherVariable); //{3}
+console.log(myOtherFunction()); //{4}
+console.log(myOtherVariable); //{5}
diff --git a/chapter01/03-Operators.html b/examples/chapter01/03-Operators.html
similarity index 100%
rename from chapter01/03-Operators.html
rename to examples/chapter01/03-Operators.html
diff --git a/chapter01/03-Operators.js b/examples/chapter01/03-Operators.js
similarity index 58%
rename from chapter01/03-Operators.js
rename to examples/chapter01/03-Operators.js
index d1044b92..7895b17b 100755
--- a/chapter01/03-Operators.js
+++ b/examples/chapter01/03-Operators.js
@@ -1,28 +1,25 @@
-/* Arithmetic operators */
-var num = 0;
+// @ts-check
+/* eslint-disable */
+/* Arithmetic operators */
+var num = 0; // {1}
console.log('num value is ' + num);
num = num + 2;
-
console.log('New num value is ' + num);
num = num * 3;
-
console.log('New num value is ' + num);
num = num / 2;
-
console.log('New num value is ' + num);
num++;
-
num--;
console.log('New num value is ' + num);
-console.log('num mod 2 value is ' + (num % 2));
-
+console.log('num mod 2 value is ' + num % 2);
/* Assignment operators */
num += 1;
@@ -45,24 +42,24 @@ console.log('num <= 1 : ' + (num <= 1));
/* Logical operators */
console.log('true && false : ' + (true && false));
console.log('true || false : ' + (true || false));
-console.log('!true : ' + (!true));
+console.log('!true : ' + !true);
/* Bitwise operators */
-console.log('5 & 1:', (5 & 1)); //same as 0101 & 0001 (result 0001 / 1)
-console.log('5 | 1:', (5 | 1)); //same as 0101 | 0001 (result 0101 / 5)
-console.log('~ 5:', (~5)); //same as ~0101 (result 1010 / 10)
-console.log('5 ^ 1:', (5 ^ 1)); //same as 0101 ^ 0001 (result 0100 / 4)
-console.log('5 << 1:', (5 << 1)); //same as 0101 << 1 (result 1010 / 10)
-console.log('5 >> 1:', (5 >> 1)); //same as 0101 >> 1 (result 0010 / 2)
+console.log('5 & 1:', 5 & 1); // same as 0101 & 0001 (result 0001 / 1)
+console.log('5 | 1:', 5 | 1); // same as 0101 | 0001 (result 0101 / 5)
+console.log('~ 5:', ~5); // same as ~0101 (result 1010 / 10)
+console.log('5 ^ 1:', 5 ^ 1); // same as 0101 ^ 0001 (result 0100 / 4)
+console.log('5 << 1:', 5 << 1); // same as 0101 << 1 (result 1010 / 10)
+console.log('5 >> 1:', 5 >> 1); // same as 0101 >> 1 (result 0010 / 2)
/* typeOf */
console.log('typeof num:', typeof num);
console.log('typeof Packt:', typeof 'Packt');
console.log('typeof true:', typeof true);
-console.log('typeof [1,2,3]:', typeof [1,2,3]);
-console.log('typeof {name:John}:', typeof {name:'John'});
+console.log('typeof [1,2,3]:', typeof [1, 2, 3]);
+console.log('typeof {name:John}:', typeof { name: 'John' });
/* delete */
-var myObj = {name: 'John', age: 21};
+var myObj = { name: 'John', age: 21 };
delete myObj.age;
-console.log(myObj); //Object {name: "John"}
\ No newline at end of file
+console.log(myObj); // Object {name: "John"}
diff --git a/chapter01/04-TruthyFalsy.html b/examples/chapter01/04-TruthyFalsy.html
similarity index 100%
rename from chapter01/04-TruthyFalsy.html
rename to examples/chapter01/04-TruthyFalsy.html
diff --git a/examples/chapter01/04-TruthyFalsy.js b/examples/chapter01/04-TruthyFalsy.js
new file mode 100644
index 00000000..c64fa3e1
--- /dev/null
+++ b/examples/chapter01/04-TruthyFalsy.js
@@ -0,0 +1,27 @@
+// @ts-check
+/* eslint-disable */
+
+function testTruthy(val) {
+ return val ? console.log('truthy') : console.log('falsy');
+}
+
+testTruthy(true); // true
+testTruthy(false); // false
+testTruthy(new Boolean(false)); // true (object is always true)
+
+testTruthy(''); // false
+testTruthy('a'); // true
+testTruthy('Packt'); // true
+testTruthy(new String('')); // true (object is always true)
+
+testTruthy(1); // true
+testTruthy(-1); // true
+testTruthy(NaN); // false
+testTruthy(new Number(NaN)); // true (object is always true)
+
+testTruthy({}); // true (object is always true)
+
+var obj = { name: 'John' };
+testTruthy(obj); // true
+testTruthy(obj.name); // true
+testTruthy(obj.age); // age (property does not exist)
diff --git a/chapter01/05-EqualsOperators.html b/examples/chapter01/05-EqualsOperators.html
similarity index 100%
rename from chapter01/05-EqualsOperators.html
rename to examples/chapter01/05-EqualsOperators.html
diff --git a/examples/chapter01/05-EqualsOperators.js b/examples/chapter01/05-EqualsOperators.js
new file mode 100644
index 00000000..d5b43ecc
--- /dev/null
+++ b/examples/chapter01/05-EqualsOperators.js
@@ -0,0 +1,39 @@
+// @ts-check
+/* eslint-disable */
+
+// Packt == true
+
+console.log('packt' ? true : false);
+// outputs true
+
+console.log('packt' == true);
+// 1 - converts Boolean using toNumber
+// 'packt' == 1
+// 2 - converts String using toNumber
+// NaN == 1
+// outputs false
+
+console.log('packt' == false);
+// 1 - converts Boolean using toNumber
+// 'packt' == 0
+// 2 - converts String using toNumber
+// NaN == 0
+// outputs false
+
+console.log([0] == true);
+// 1 - converts Boolean using toNumber
+// [0] == 1
+// 2 - converts Object using toPrimitive
+// 2.1 - [0].valueOf() is not primitive
+// 2.2 - [0].toString is 0
+// 0 == 1
+// outputs false
+
+//* ****************************** ===
+console.log('packt' === true); // false
+
+console.log('packt' === 'packt'); // true
+
+var person1 = { name: 'John' };
+var person2 = { name: 'John' };
+console.log(person1 === person2); // false, different objects
diff --git a/chapter01/06-ConditionalStatements.html b/examples/chapter01/06-ConditionalStatements.html
similarity index 100%
rename from chapter01/06-ConditionalStatements.html
rename to examples/chapter01/06-ConditionalStatements.html
diff --git a/examples/chapter01/06-ConditionalStatements.js b/examples/chapter01/06-ConditionalStatements.js
new file mode 100644
index 00000000..c939967c
--- /dev/null
+++ b/examples/chapter01/06-ConditionalStatements.js
@@ -0,0 +1,54 @@
+// @ts-check
+/* eslint-disable */
+
+/* Example 01 - if */
+var num = 1;
+if (num === 1) {
+ console.log('num is equal to 1');
+}
+
+/* Example 02 - if-else */
+var num = 0;
+if (num === 1) {
+ console.log('num is equal to 1');
+} else {
+ console.log('num is not equal to 1, the value of num is ' + num);
+}
+
+/* Example 03 - if-else-if-else... */
+var month = 5;
+if (month === 1) {
+ console.log('January');
+} else if (month === 2) {
+ console.log('February');
+} else if (month === 3) {
+ console.log('March');
+} else {
+ console.log('Month is not January, February or March');
+}
+
+/* Example 04 - switch */
+var month = 5;
+switch (month) {
+ case 1:
+ console.log('January');
+ break;
+ case 2:
+ console.log('February');
+ break;
+ case 3:
+ console.log('March');
+ break;
+ default:
+ console.log('Month is not January, February or March');
+}
+
+/* Example 05 - ternary operator - if..else */
+if (num === 1) {
+ num--;
+} else {
+ num++;
+}
+
+// is the same as
+num === 1 ? num-- : num++;
diff --git a/chapter01/07-Loops.html b/examples/chapter01/07-Loops.html
similarity index 100%
rename from chapter01/07-Loops.html
rename to examples/chapter01/07-Loops.html
diff --git a/chapter01/07-Loops.js b/examples/chapter01/07-Loops.js
similarity index 56%
rename from chapter01/07-Loops.js
rename to examples/chapter01/07-Loops.js
index 61cf20cb..9d12b19e 100755
--- a/chapter01/07-Loops.js
+++ b/examples/chapter01/07-Loops.js
@@ -1,23 +1,24 @@
-console.log('**** for example ****');
+// @ts-check
+/* eslint-disable */
+console.log('**** for example ****');
/* for - example */
-for (var i=0; i<10; i++) {
- console.log(i);
+for (var i = 0; i < 10; i++) {
+ console.log(i);
}
console.log('**** while example ****');
/* while - example */
var i = 0;
-while(i<10)
-{
- console.log(i);
- i++;
+while (i < 10) {
+ console.log(i);
+ i++;
}
console.log('**** do-while example ****');
/* do-while - example */
var i = 0;
do {
- console.log(i);
- i++;
-} while (i<10)
\ No newline at end of file
+ console.log(i);
+ i++;
+} while (i < 10);
diff --git a/chapter01/08-Functions.html b/examples/chapter01/08-Functions.html
similarity index 100%
rename from chapter01/08-Functions.html
rename to examples/chapter01/08-Functions.html
diff --git a/chapter01/08-Functions.js b/examples/chapter01/08-Functions.js
similarity index 66%
rename from chapter01/08-Functions.js
rename to examples/chapter01/08-Functions.js
index 9915e566..52d5f9c8 100644
--- a/chapter01/08-Functions.js
+++ b/examples/chapter01/08-Functions.js
@@ -1,12 +1,15 @@
+// @ts-check
+/* eslint-disable */
+
function sayHello() {
- console.log('Hello!');
+ console.log('Hello!');
}
sayHello();
/* function with parameter */
function output(text) {
- console.log(text);
+ console.log(text);
}
output('Hello!');
@@ -17,13 +20,8 @@ output();
/* function using the return statement */
function sum(num1, num2) {
- return num1 + num2;
+ return num1 + num2;
}
-var result = sum(1,2);
+var result = sum(1, 2);
output(result);
-
-
-
-
-
diff --git a/chapter01/10-ObjectOrientedJS.html b/examples/chapter01/09-ObjectOrientedJS.html
similarity index 59%
rename from chapter01/10-ObjectOrientedJS.html
rename to examples/chapter01/09-ObjectOrientedJS.html
index 1b3848bd..cfbe1a04 100644
--- a/chapter01/10-ObjectOrientedJS.html
+++ b/examples/chapter01/09-ObjectOrientedJS.html
@@ -5,6 +5,6 @@
-
+
-