├── week-4 ├── d3-context-bind-call-apply │ ├── notes │ │ ├── call-and-apply.js │ │ ├── Context-Flowchart.jpg │ │ └── demo.js │ ├── practices │ │ ├── 02-bind │ │ │ ├── test.js │ │ │ ├── employee.js │ │ │ └── README.md │ │ ├── 04-context-arrow-functions │ │ │ ├── classes │ │ │ │ └── user.js │ │ │ ├── index.js │ │ │ ├── review.js │ │ │ └── README.md │ │ ├── 03-call-apply │ │ │ ├── greet.js │ │ │ ├── classes │ │ │ │ └── gradebook.js │ │ │ ├── grade.js │ │ │ └── README.md │ │ └── 01-context-regular-functions │ │ │ ├── README.md │ │ │ └── context.js │ └── key-takeaways.md ├── d5-es5-class-syntax │ ├── practices │ │ ├── 02-es5-classes │ │ │ ├── classes │ │ │ │ ├── array.js │ │ │ │ ├── dog.js │ │ │ │ └── person.js │ │ │ ├── package.json │ │ │ ├── test │ │ │ │ ├── array-spec.js │ │ │ │ └── dog-spec.js │ │ │ └── README.md │ │ └── 01-custom-error-types │ │ │ ├── error-types │ │ │ ├── validation-error.js │ │ │ └── maximum-length-exceeded-error.js │ │ │ ├── package.json │ │ │ └── test │ │ │ ├── validation-error-spec.js │ │ │ └── maximum-length-exceeded-error-spec.js │ ├── key-takeaways.md │ └── notes │ │ └── es5-syntax.js ├── d2-es6-classes │ ├── practices │ │ ├── 01-common-js-modules │ │ │ ├── messages │ │ │ │ ├── hello-message.js │ │ │ │ ├── say-message.js │ │ │ │ └── index.js │ │ │ ├── send-messages │ │ │ │ ├── say-hello-to.js │ │ │ │ └── give-message-to-mrs-potato.js │ │ │ ├── index.js │ │ │ └── README.md │ │ ├── 02-basic-class-syntax │ │ │ ├── classes │ │ │ │ └── person.js │ │ │ ├── package.json │ │ │ ├── README.md │ │ │ └── test │ │ │ │ └── person-spec.js │ │ ├── 03-inheritance │ │ │ ├── classes │ │ │ │ ├── student.js │ │ │ │ ├── teacher.js │ │ │ │ └── person.js │ │ │ ├── package.json │ │ │ ├── test │ │ │ │ ├── student-spec.js │ │ │ │ └── teacher-spec.js │ │ │ └── README.md │ │ └── 04-polymorphism │ │ │ ├── package.json │ │ │ ├── classes │ │ │ ├── teacher.js │ │ │ ├── student.js │ │ │ └── person.js │ │ │ ├── README.md │ │ │ └── test │ │ │ └── introduce-spec.js │ ├── notes │ │ ├── other │ │ │ └── multiplication.js │ │ ├── classes-commonJS-modules │ │ │ ├── sales.js │ │ │ ├── program.js │ │ │ └── accounting.js │ │ ├── import-export │ │ │ ├── subtraction.js │ │ │ ├── main.js │ │ │ ├── adding.js │ │ │ └── commonJS.md │ │ ├── demo.js │ │ ├── book.js │ │ └── wallet.js │ └── key-takeaways.md ├── w4-review-guide │ ├── w4-anki │ │ ├── TDD.apkg │ │ └── JS+Errors.apkg │ └── oop-reference-js.md.pdf ├── d1-basic-coding-principles │ ├── key-takeaways.md │ ├── practices │ │ ├── 03-dry │ │ │ ├── package.json │ │ │ ├── README.md │ │ │ └── practice.js │ │ ├── 01-reading-tests-exercise │ │ │ └── README.md │ │ └── 02-single-responsibility-principle │ │ │ ├── package.json │ │ │ └── README.md │ └── notes │ │ └── srp-dry.md ├── d4-test-driven-development │ ├── practices │ │ ├── 02-unit-testing │ │ │ ├── funcs.js │ │ │ ├── package.json │ │ │ ├── README.md │ │ │ ├── test │ │ │ │ └── class-spec.js │ │ │ └── class.js │ │ └── 01-error-handling │ │ │ ├── error-handling.js │ │ │ └── README.md │ ├── key-takeaways.md │ └── notes │ │ ├── demo.js │ │ └── error-syntax-notes.md └── w4-long-practice-solutions │ └── wk4-long-practice-solutions.md ├── .gitignore ├── week-6 ├── d2-binary-search-merge-quicksort │ ├── practices │ │ ├── 02-merge-sort │ │ │ ├── .gitignore │ │ │ ├── package.json │ │ │ ├── merge-sort.js │ │ │ └── test │ │ │ │ └── merge-sort-specs.js │ │ ├── 03-quicksort │ │ │ ├── .gitignore │ │ │ ├── package.json │ │ │ ├── quicksort.js │ │ │ └── test │ │ │ │ └── quicksort-specs.js │ │ └── 01-binary-search │ │ │ ├── .gitignore │ │ │ ├── package.json │ │ │ ├── binary-search.js │ │ │ └── test │ │ │ └── search-specs.js │ ├── key-takeaways.md │ └── notes │ │ ├── quick-sort.js │ │ ├── binarySearch.js │ │ ├── merge-sort.js │ │ └── array-sort-method.js ├── d1-sorting-bubble-insertion-selection │ ├── practices │ │ ├── 01-bubble-sort │ │ │ ├── .gitignore │ │ │ ├── package.json │ │ │ ├── bubble-sort.js │ │ │ └── test │ │ │ │ └── sort-specs.js │ │ ├── 02-insertion-sort │ │ │ ├── .gitignore │ │ │ ├── package.json │ │ │ ├── insertion-sort.js │ │ │ └── test │ │ │ │ └── sort-specs.js │ │ └── 03-selection-sort │ │ │ ├── .gitignore │ │ │ ├── package.json │ │ │ ├── selection-sort.js │ │ │ └── test │ │ │ └── sort-specs.js │ ├── notes │ │ ├── Untitled design.jpg │ │ ├── insertion.js │ │ ├── selection-sort.js │ │ └── bubbleSort.js │ └── key-takeaways.md ├── d5-whiteboarding │ └── key-takeaways.md ├── w6-long-practice-solutions │ └── w6-long-practice-solutions.md ├── d4-graphs │ ├── key-takeaways.md │ ├── practices │ │ ├── 02-social-graph-practice │ │ │ ├── package.json │ │ │ ├── social.js │ │ │ └── README-pt2.md │ │ └── 01-graph-repl-problems │ │ │ ├── morning-practice │ │ │ ├── 06-degress-of-separation-bfs.js │ │ │ ├── 04-simple-breadth-first-search.js │ │ │ ├── 05-a-shortest-path-bfs.js │ │ │ └── 03-refactor-bft.js │ │ │ └── homework │ │ │ ├── 02-simple-depth-first-traversal.js │ │ │ └── 01-simple-breadth-first-traversal.js │ └── notes │ │ ├── graph-traverals.js │ │ └── graphs.js └── d3-binary-search-trees │ ├── practices │ └── 01-binary-search-trees │ │ ├── package.json │ │ ├── README-pt2.md │ │ ├── binary-search-tree.js │ │ ├── README-pt3.md │ │ ├── README-pt1.md │ │ ├── README-pt4.md │ │ └── README.md │ ├── key-takeaways.md │ └── notes │ ├── binary-search-trees.md │ └── tree-traversal.md ├── week-5 ├── d2-binary-hexa-ascii-memory-arrays │ ├── practices │ │ ├── memory-discussion.md │ │ ├── 03-dynamic-arrays │ │ │ ├── dynamic-array.js │ │ │ ├── package.json │ │ │ └── test │ │ │ │ └── dynamic-array-practice-specs.js │ │ ├── 01-binary-hexa-conversion-functions │ │ │ ├── package.json │ │ │ ├── binary-hexa-conversion-functions.js │ │ │ └── README.md │ │ └── 02-ascii-advanced-conversion-functions │ │ │ ├── package.json │ │ │ ├── ascii-advanced-conversion-functions.js │ │ │ └── README.md │ ├── notes │ │ ├── image.png │ │ ├── logic-and-truth.md │ │ ├── arrays.md │ │ └── stacks.js │ └── key-takeaways.md ├── d1-big-o-arrays │ ├── notes │ │ ├── big-O-graph.png │ │ ├── array-sorting-algos.png │ │ ├── data-structure-operations.png │ │ └── demo.js │ ├── key-takeaways.md │ ├── practices │ │ └── 01-timing-benchmarks │ │ │ ├── phase-1.js │ │ │ ├── phase-3.js │ │ │ ├── package.json │ │ │ ├── phase-2.js │ │ │ ├── README.md │ │ │ ├── README-phase-1.md │ │ │ ├── README-phase-3.md │ │ │ ├── README-phase-2.md │ │ │ └── test │ │ │ └── phase-1-spec.js │ └── extra-practice │ │ └── big-o-intro-extra-practice │ │ ├── 02-anagrams.js │ │ ├── 04-execution-time-differences.js │ │ ├── 03-two-sum.js │ │ ├── 01-big-octopus.js │ │ └── solutions │ │ ├── 01-big-octopus.js │ │ ├── 04-execution-time-difference.js │ │ ├── 02-anagram.js │ │ └── 03-two-sum.js ├── d3-linked-lists-and-queues │ ├── notes │ │ └── linked-lists.jpeg │ ├── key-takeaways.md │ └── practices │ │ └── 01-linked-lists │ │ ├── linked-list-timing.js │ │ ├── package.json │ │ ├── README-phase-1.md │ │ ├── README-phase-3.md │ │ ├── linked-list.js │ │ ├── doubly-linked-list.js │ │ ├── README-phase-2.md │ │ ├── README.md │ │ └── test │ │ └── linked-list-practice-specs.js ├── d5-whiteboarding │ └── key-takeaways.md ├── d4-hash-tables-and-sets │ ├── key-takeaways.md │ ├── practices │ │ └── 01-hash-tables │ │ │ ├── package.json │ │ │ ├── hash-table.js │ │ │ ├── README-pt2.md │ │ │ ├── test │ │ │ ├── hash-table-pt3-spec.js │ │ │ ├── hash-table-pt4-spec.js │ │ │ ├── hash-table-pt2-spec.js │ │ │ └── hash-table-pt1-spec.js │ │ │ ├── README-pt3.md │ │ │ ├── README-pt1.md │ │ │ └── README-pt4.md │ └── notes │ │ ├── sets.md │ │ └── tabulation.js ├── w5-long-practice-solutions │ └── w5-long-practice-solutions.md └── w5-review-guide │ └── conversion-extra-practice │ ├── conversion-practice.js │ └── conversion-practice-solution.js └── git-flow-guide └── images ├── new-repo-config.png ├── new-repo-invite.png ├── cloning-repo-cli.png ├── create-repo-left.png ├── create-repo-right.png ├── cloning-repo-github.png ├── cloning-repo-success.png ├── create-repo-navigate.png ├── connecting-repo-check-remote.png ├── connecting-repo-initial-push.png ├── connecting-repo-change-remote.png └── connecting-repo-branch-name-change.png /week-4/d3-context-bind-call-apply/notes/call-and-apply.js: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | **/node_modules 2 | **/.DS_STORE 3 | **/aa-solutions 4 | -------------------------------------------------------------------------------- /week-4/d3-context-bind-call-apply/practices/02-bind/test.js: -------------------------------------------------------------------------------- 1 | // Your code here 2 | -------------------------------------------------------------------------------- /week-4/d3-context-bind-call-apply/practices/02-bind/employee.js: -------------------------------------------------------------------------------- 1 | // Your code here 2 | -------------------------------------------------------------------------------- /week-6/d2-binary-search-merge-quicksort/practices/02-merge-sort/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules -------------------------------------------------------------------------------- /week-6/d2-binary-search-merge-quicksort/practices/03-quicksort/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules -------------------------------------------------------------------------------- /week-4/d5-es5-class-syntax/practices/02-es5-classes/classes/array.js: -------------------------------------------------------------------------------- 1 | // Your code here 2 | -------------------------------------------------------------------------------- /week-6/d1-sorting-bubble-insertion-selection/practices/01-bubble-sort/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules -------------------------------------------------------------------------------- /week-6/d2-binary-search-merge-quicksort/practices/01-binary-search/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules -------------------------------------------------------------------------------- /week-5/d2-binary-hexa-ascii-memory-arrays/practices/memory-discussion.md: -------------------------------------------------------------------------------- 1 | # Official answer: 2 | -------------------------------------------------------------------------------- /week-6/d1-sorting-bubble-insertion-selection/practices/02-insertion-sort/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules -------------------------------------------------------------------------------- /week-6/d1-sorting-bubble-insertion-selection/practices/03-selection-sort/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules -------------------------------------------------------------------------------- /week-4/d2-es6-classes/practices/01-common-js-modules/messages/hello-message.js: -------------------------------------------------------------------------------- 1 | const helloMessage = "Greetings! Let us begin!"; 2 | -------------------------------------------------------------------------------- /week-4/w4-review-guide/w4-anki/TDD.apkg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appacademy/Module-2-Resources/HEAD/week-4/w4-review-guide/w4-anki/TDD.apkg -------------------------------------------------------------------------------- /git-flow-guide/images/new-repo-config.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appacademy/Module-2-Resources/HEAD/git-flow-guide/images/new-repo-config.png -------------------------------------------------------------------------------- /git-flow-guide/images/new-repo-invite.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appacademy/Module-2-Resources/HEAD/git-flow-guide/images/new-repo-invite.png -------------------------------------------------------------------------------- /git-flow-guide/images/cloning-repo-cli.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appacademy/Module-2-Resources/HEAD/git-flow-guide/images/cloning-repo-cli.png -------------------------------------------------------------------------------- /git-flow-guide/images/create-repo-left.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appacademy/Module-2-Resources/HEAD/git-flow-guide/images/create-repo-left.png -------------------------------------------------------------------------------- /git-flow-guide/images/create-repo-right.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appacademy/Module-2-Resources/HEAD/git-flow-guide/images/create-repo-right.png -------------------------------------------------------------------------------- /week-5/d1-big-o-arrays/notes/big-O-graph.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appacademy/Module-2-Resources/HEAD/week-5/d1-big-o-arrays/notes/big-O-graph.png -------------------------------------------------------------------------------- /git-flow-guide/images/cloning-repo-github.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appacademy/Module-2-Resources/HEAD/git-flow-guide/images/cloning-repo-github.png -------------------------------------------------------------------------------- /git-flow-guide/images/cloning-repo-success.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appacademy/Module-2-Resources/HEAD/git-flow-guide/images/cloning-repo-success.png -------------------------------------------------------------------------------- /git-flow-guide/images/create-repo-navigate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appacademy/Module-2-Resources/HEAD/git-flow-guide/images/create-repo-navigate.png -------------------------------------------------------------------------------- /week-4/w4-review-guide/oop-reference-js.md.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appacademy/Module-2-Resources/HEAD/week-4/w4-review-guide/oop-reference-js.md.pdf -------------------------------------------------------------------------------- /week-4/w4-review-guide/w4-anki/JS+Errors.apkg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appacademy/Module-2-Resources/HEAD/week-4/w4-review-guide/w4-anki/JS+Errors.apkg -------------------------------------------------------------------------------- /week-4/d2-es6-classes/notes/other/multiplication.js: -------------------------------------------------------------------------------- 1 | function multiplication(num1, num2) { 2 | return num1 * num2; 3 | } 4 | 5 | module.exports = { multiplication }; -------------------------------------------------------------------------------- /git-flow-guide/images/connecting-repo-check-remote.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appacademy/Module-2-Resources/HEAD/git-flow-guide/images/connecting-repo-check-remote.png -------------------------------------------------------------------------------- /git-flow-guide/images/connecting-repo-initial-push.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appacademy/Module-2-Resources/HEAD/git-flow-guide/images/connecting-repo-initial-push.png -------------------------------------------------------------------------------- /week-4/d1-basic-coding-principles/key-takeaways.md: -------------------------------------------------------------------------------- 1 | # Be able to: 2 | - Understand the concepts of DRY and SRP 3 | - Refactor code to make it more DRY and SRP minded. 4 | -------------------------------------------------------------------------------- /week-5/d1-big-o-arrays/notes/array-sorting-algos.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appacademy/Module-2-Resources/HEAD/week-5/d1-big-o-arrays/notes/array-sorting-algos.png -------------------------------------------------------------------------------- /git-flow-guide/images/connecting-repo-change-remote.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appacademy/Module-2-Resources/HEAD/git-flow-guide/images/connecting-repo-change-remote.png -------------------------------------------------------------------------------- /week-5/d1-big-o-arrays/notes/data-structure-operations.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appacademy/Module-2-Resources/HEAD/week-5/d1-big-o-arrays/notes/data-structure-operations.png -------------------------------------------------------------------------------- /week-5/d2-binary-hexa-ascii-memory-arrays/notes/image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appacademy/Module-2-Resources/HEAD/week-5/d2-binary-hexa-ascii-memory-arrays/notes/image.png -------------------------------------------------------------------------------- /week-5/d3-linked-lists-and-queues/notes/linked-lists.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appacademy/Module-2-Resources/HEAD/week-5/d3-linked-lists-and-queues/notes/linked-lists.jpeg -------------------------------------------------------------------------------- /git-flow-guide/images/connecting-repo-branch-name-change.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appacademy/Module-2-Resources/HEAD/git-flow-guide/images/connecting-repo-branch-name-change.png -------------------------------------------------------------------------------- /week-4/d3-context-bind-call-apply/notes/Context-Flowchart.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appacademy/Module-2-Resources/HEAD/week-4/d3-context-bind-call-apply/notes/Context-Flowchart.jpg -------------------------------------------------------------------------------- /week-4/d2-es6-classes/practices/01-common-js-modules/messages/say-message.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | function sayMessage(message) { 4 | console.log(`"${message}"`) 5 | } 6 | 7 | sayMessage(helloMessage); 8 | -------------------------------------------------------------------------------- /week-4/d2-es6-classes/practices/01-common-js-modules/send-messages/say-hello-to.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | function sayHelloTo(name) { 4 | sayMessage(`Hello ${name}!`) 5 | } 6 | 7 | sayHelloTo("Woody"); 8 | -------------------------------------------------------------------------------- /week-6/d1-sorting-bubble-insertion-selection/notes/Untitled design.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appacademy/Module-2-Resources/HEAD/week-6/d1-sorting-bubble-insertion-selection/notes/Untitled design.jpg -------------------------------------------------------------------------------- /week-4/d2-es6-classes/notes/classes-commonJS-modules/sales.js: -------------------------------------------------------------------------------- 1 | class Client { 2 | constructor(name, address) { 3 | this.name = name; 4 | this.address = address; 5 | } 6 | } 7 | 8 | exports.Client = Client; 9 | -------------------------------------------------------------------------------- /week-4/d5-es5-class-syntax/key-takeaways.md: -------------------------------------------------------------------------------- 1 | # Be able to: 2 | - Recognize ES5 class syntax. 3 | - Use constructor functions to make a class type object in ES5. 4 | - Add methods to the Prototype. 5 | - Convert ES5 to ES6 classes. 6 | -------------------------------------------------------------------------------- /week-5/d5-whiteboarding/key-takeaways.md: -------------------------------------------------------------------------------- 1 | # Be able too: 2 | - Use Polya's problem solving framework to solve complex problems. 3 | - Describe your plan and your code to another person. 4 | - Optimize solutions for complexity. 5 | -------------------------------------------------------------------------------- /week-6/d5-whiteboarding/key-takeaways.md: -------------------------------------------------------------------------------- 1 | # Be able too: 2 | - Use Polya's problem solving framework to solve complex problems. 3 | - Describe your plan and your code to another person. 4 | - Optimize solutions for complexity. 5 | -------------------------------------------------------------------------------- /week-4/d3-context-bind-call-apply/key-takeaways.md: -------------------------------------------------------------------------------- 1 | # Be able to: 2 | - Define and identify the context of an object. 3 | - Maintain context by use of call, bind and apply. 4 | - Identify the differences and the use cases for call, bind and apply. 5 | -------------------------------------------------------------------------------- /week-6/d1-sorting-bubble-insertion-selection/key-takeaways.md: -------------------------------------------------------------------------------- 1 | # Be able to: 2 | 3 | - Describe a logarithmic function and it's behavior. 4 | - Describe bubble sort, selection sort, and insertion sort by their behavior and why they may be problematic. 5 | -------------------------------------------------------------------------------- /week-4/d2-es6-classes/notes/import-export/subtraction.js: -------------------------------------------------------------------------------- 1 | function subtraction(a, b) { 2 | if (a > b) return a - b; 3 | return b - a; 4 | } 5 | 6 | module.exports = subtraction; 7 | // module.exports.taco = subtraction; 8 | // module.exports = {taco: subtraction} 9 | -------------------------------------------------------------------------------- /week-4/d2-es6-classes/practices/01-common-js-modules/send-messages/give-message-to-mrs-potato.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | function giveMessageToMrsPotato(message) { 4 | sayHelloTo("Mrs. Potato"); 5 | console.log(`(Psst... ${message})`) 6 | } 7 | 8 | giveMessageToMrsPotato("Hi Buzz"); 9 | -------------------------------------------------------------------------------- /week-4/d2-es6-classes/practices/01-common-js-modules/messages/index.js: -------------------------------------------------------------------------------- 1 | const message1 = "You are looking very spudly today!"; 2 | const message2 = "There's a good deal on mattresses tomorrow."; 3 | const message3 = "Do you like to do things in unnecessarily complicated ways?"; 4 | -------------------------------------------------------------------------------- /week-5/d1-big-o-arrays/key-takeaways.md: -------------------------------------------------------------------------------- 1 | # Be able to: 2 | 3 | - Identify the BigO space and time complexity of functions. 4 | - Be able to simplify expressions of BigO down to the worst case scenario. 5 | - Be able to time your code using console.time() and console.timeEnd() and Date.now(). 6 | -------------------------------------------------------------------------------- /week-4/d3-context-bind-call-apply/practices/04-context-arrow-functions/classes/user.js: -------------------------------------------------------------------------------- 1 | class User { 2 | constructor(name) { 3 | this.name = name; 4 | } 5 | 6 | changeName(newName) { 7 | this.name = newName; 8 | return this.name; 9 | } 10 | } 11 | 12 | module.exports = User; -------------------------------------------------------------------------------- /week-5/d2-binary-hexa-ascii-memory-arrays/key-takeaways.md: -------------------------------------------------------------------------------- 1 | # Be able to: 2 | 3 | - Convert binary and hexadecimal to decimal, and vice versa. 4 | - Be able to complete a truth table. 5 | - Be able to identify the time and space complexity of array methods. 6 | - Be able to identify and set up a stack in javascript (LIFO). 7 | -------------------------------------------------------------------------------- /week-4/d4-test-driven-development/practices/02-unit-testing/funcs.js: -------------------------------------------------------------------------------- 1 | function isFive(num) { 2 | // Your code here 3 | } 4 | 5 | function isOdd(number) { 6 | // Your code here 7 | } 8 | 9 | function myRange(min, max, step = 1) { 10 | // Your code here 11 | } 12 | 13 | 14 | module.exports = { isFive, isOdd, myRange }; 15 | -------------------------------------------------------------------------------- /week-5/d3-linked-lists-and-queues/key-takeaways.md: -------------------------------------------------------------------------------- 1 | # Be able to: 2 | - Implement an array based queue and describe. 3 | - Implement a single and double linked list and describe. 4 | - Identify properties of an individual node (value, next, prev) and the list (head, tail). 5 | - Identify the BigO of methods on queues and linked lists. 6 | -------------------------------------------------------------------------------- /week-6/d2-binary-search-merge-quicksort/key-takeaways.md: -------------------------------------------------------------------------------- 1 | # Be able to: 2 | 3 | - Describe binary search, merge and quick sort and be able to identify each based on descriptions of behavior. 4 | - Identify best and worse case complexity of each. 5 | - Use the built in array.sort() method and be able to create compare functions to use with .sort(). 6 | -------------------------------------------------------------------------------- /week-6/w6-long-practice-solutions/w6-long-practice-solutions.md: -------------------------------------------------------------------------------- 1 | ## Week 6 Long Practice Solutions 2 | 3 | ### These solutions will be added by the EOD the day of each long practice. 4 | 5 | - D2 6 | - Custom Sorts Long Practice 7 | - D3 8 | - Binary Tree Long Practice 9 | - D4 10 | - Solving Graph Problems Long Practice 11 | -------------------------------------------------------------------------------- /week-5/d1-big-o-arrays/practices/01-timing-benchmarks/phase-1.js: -------------------------------------------------------------------------------- 1 | // Adds up positive integers from 1-n 2 | function addNums(n) { 3 | // Fill this in 4 | } 5 | 6 | 7 | // Adds up values of addNums(1) through addNums(n) 8 | function addManyNums(n) { 9 | // Fill this in 10 | } 11 | 12 | 13 | 14 | module.exports = [addNums, addManyNums]; 15 | -------------------------------------------------------------------------------- /week-4/d3-context-bind-call-apply/practices/03-call-apply/greet.js: -------------------------------------------------------------------------------- 1 | // DO NOT MODIFY THE say FUNCTION 2 | function say(name) { 3 | console.log(`${this.message} ${name}!`); 4 | } 5 | 6 | helloMessage = { message: 'Hello,' }; 7 | heyThereMessage = { message: 'Hey there,' }; 8 | 9 | say(helloMessage, "John"); 10 | say(heyThereMessage, "Michael"); 11 | -------------------------------------------------------------------------------- /week-5/d1-big-o-arrays/practices/01-timing-benchmarks/phase-3.js: -------------------------------------------------------------------------------- 1 | const [addNums, addManyNums] = require("./phase-1"); 2 | 3 | 4 | 5 | n = 1000 6 | console.log(`addNums(${n}): `); 7 | addNums10Timing(10000000); 8 | 9 | console.log("\n***********\n"); 10 | 11 | n = 1000 12 | console.log(`addManyNums(${n}): `); 13 | addManyNums10Timing(1000); 14 | -------------------------------------------------------------------------------- /week-4/d2-es6-classes/practices/02-basic-class-syntax/classes/person.js: -------------------------------------------------------------------------------- 1 | // Your code here 2 | 3 | /****************************************************************************/ 4 | /******************* DO NOT EDIT CODE BELOW THIS LINE ***********************/ 5 | 6 | try { 7 | module.exports = Person; 8 | } catch { 9 | module.exports = null; 10 | } 11 | -------------------------------------------------------------------------------- /week-6/d4-graphs/key-takeaways.md: -------------------------------------------------------------------------------- 1 | # Be able to: 2 | - Construct a graph from an adjacency list or an adjacency matrix. 3 | - Perform breadth-first, depth-first traversals and searches of a graph. 4 | - Use the strategies for breadth-first and depth-first methods to solve graphing problems. 5 | - Identify the shortest path from one node to another in a graph using BFS. 6 | -------------------------------------------------------------------------------- /week-6/d4-graphs/practices/02-social-graph-practice/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "social-graph-practice", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "social.js", 6 | "scripts": { 7 | "test": "mocha" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "chai": "^4.3.4", 13 | "mocha": "^8.3.2" 14 | } 15 | } -------------------------------------------------------------------------------- /week-5/d3-linked-lists-and-queues/practices/01-linked-lists/linked-list-timing.js: -------------------------------------------------------------------------------- 1 | const LinkedList = require('./linked-list.js'); 2 | const DoublyLinkedList = require('./doubly-linked-list.js'); 3 | 4 | /* 5 | Construct a timing test to verify the time complexities of `addToHead` and 6 | `addToTail` for both singly and doubly linked lists. 7 | */ 8 | 9 | // Your code here 10 | -------------------------------------------------------------------------------- /week-4/d2-es6-classes/notes/import-export/main.js: -------------------------------------------------------------------------------- 1 | const { adding, subtraction, division } = require('./adding') 2 | // const subtraction = require('./subtraction') 3 | const { multiplication: taco } = require('../other/multiplication') 4 | 5 | 6 | console.log(adding(5, 7)) //=> 12 7 | console.log(subtraction(8, 3)) //=> 5 8 | console.log(subtraction(2, 7)) // => 5 9 | console.log(taco(2,3)) -------------------------------------------------------------------------------- /week-4/d5-es5-class-syntax/practices/01-custom-error-types/error-types/validation-error.js: -------------------------------------------------------------------------------- 1 | // Your code here 2 | 3 | /****************************************************************************/ 4 | /******************* DO NOT EDIT CODE BELOW THIS LINE ***********************/ 5 | 6 | try { 7 | module.exports = ValidationError; 8 | } catch { 9 | module.exports = null; 10 | } 11 | -------------------------------------------------------------------------------- /week-5/d3-linked-lists-and-queues/practices/01-linked-lists/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "linked-list-practice", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "linked-list.js", 6 | "scripts": { 7 | "test": "mocha" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "chai": "^4.3.4", 13 | "mocha": "^8.3.2" 14 | } 15 | } -------------------------------------------------------------------------------- /week-5/d4-hash-tables-and-sets/key-takeaways.md: -------------------------------------------------------------------------------- 1 | # Be able to: 2 | - Describe the time complexities of a hash table and its methods. 3 | - Describe teh time complexities of a set and its methods. 4 | - Identify when using each would be useful in optimizing code (most importantly array methods). 5 | - Understand what a hashing function does and what the hash mod function does. 6 | -------------------------------------------------------------------------------- /week-4/d1-basic-coding-principles/practices/03-dry/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "DRY", 3 | "version": "1.0.0", 4 | "description": "Practice with DRY", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "mocha" 8 | }, 9 | "keywords": [], 10 | "author": "", 11 | "license": "ISC", 12 | "dependencies": { 13 | "chai": "^4.3.4", 14 | "mocha": "^9.0.3" 15 | } 16 | } -------------------------------------------------------------------------------- /week-5/d2-binary-hexa-ascii-memory-arrays/practices/03-dynamic-arrays/dynamic-array.js: -------------------------------------------------------------------------------- 1 | class DynamicArray { 2 | 3 | constructor(defaultSize=4) { 4 | 5 | // Your code here 6 | 7 | } 8 | 9 | read(index) { 10 | 11 | // Your code here 12 | } 13 | 14 | unshift(val) { 15 | 16 | // Your code here 17 | } 18 | 19 | } 20 | 21 | 22 | module.exports = DynamicArray; 23 | -------------------------------------------------------------------------------- /week-4/d2-es6-classes/practices/01-common-js-modules/index.js: -------------------------------------------------------------------------------- 1 | 2 | // Your code here 3 | 4 | /****************************************************************************/ 5 | /******************* DO NOT EDIT CODE BELOW THIS LINE ***********************/ 6 | 7 | sayHelloTo("Mr. Potato"); 8 | giveMessageToMrsPotato(msg1); 9 | giveMessageToMrsPotato(msg2); 10 | giveMessageToMrsPotato(msg3); 11 | -------------------------------------------------------------------------------- /week-5/d1-big-o-arrays/practices/01-timing-benchmarks/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "timing-benchmarks-practice", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "timing-benchmarks.js", 6 | "scripts": { 7 | "test": "mocha" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "chai": "^4.3.4", 13 | "mocha": "^8.3.2" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /week-5/d2-binary-hexa-ascii-memory-arrays/practices/03-dynamic-arrays/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "dynamic-array-practice", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "array.js", 6 | "scripts": { 7 | "test": "mocha" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "chai": "^4.3.4", 13 | "mocha": "^8.3.2" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /week-4/d2-es6-classes/practices/03-inheritance/classes/student.js: -------------------------------------------------------------------------------- 1 | const Person = require('./person'); 2 | 3 | // Your code here 4 | 5 | /****************************************************************************/ 6 | /******************* DO NOT EDIT CODE BELOW THIS LINE ***********************/ 7 | 8 | try { 9 | module.exports = Student; 10 | } catch { 11 | module.exports = null; 12 | } 13 | -------------------------------------------------------------------------------- /week-4/d2-es6-classes/practices/03-inheritance/classes/teacher.js: -------------------------------------------------------------------------------- 1 | const Person = require('./person'); 2 | 3 | // Your code here 4 | 5 | /****************************************************************************/ 6 | /******************* DO NOT EDIT CODE BELOW THIS LINE ***********************/ 7 | 8 | try { 9 | module.exports = Teacher; 10 | } catch { 11 | module.exports = null; 12 | } 13 | -------------------------------------------------------------------------------- /week-6/d4-graphs/notes/graph-traverals.js: -------------------------------------------------------------------------------- 1 | /* 2 | You will utilize several different methods of traversing graphs. These include: 3 | -breadth-first 4 | -depth-first 5 | -pre-order 6 | -in-order 7 | -post-order 8 | 9 | These refer to the patterns in which the algorithm will access each node of the graph, 10 | depending on factors such as directed or undirected edges and weights. 11 | 12 | 13 | */ -------------------------------------------------------------------------------- /week-4/w4-long-practice-solutions/wk4-long-practice-solutions.md: -------------------------------------------------------------------------------- 1 | ## Week 4 Long Practice Solutions 2 | 3 | ### These solutions will be added by the EOD the day of each long practice. 4 | 5 | - D2 6 | - Friendly and Evil Dragons Long Practice 7 | - Class Syntax with Employees and Managers Long Practice 8 | - D3 9 | - Context Long Practice 10 | - D4 11 | - Test Driven Design Long Practice 12 | -------------------------------------------------------------------------------- /week-4/d2-es6-classes/notes/classes-commonJS-modules/program.js: -------------------------------------------------------------------------------- 1 | const sales = require('./sales'); 2 | const { Invoice, Receipt } = require('./accounting'); 3 | 4 | const client = new sales.Client('Big Business, Inc.', '1 Corporate Drive.'); 5 | const invoice = new Invoice('111-R1-20', client); 6 | const receipt = new Receipt(4, '4/6/21') 7 | console.log(receipt) 8 | 9 | console.log(invoice.getClientName()); 10 | -------------------------------------------------------------------------------- /week-5/d4-hash-tables-and-sets/practices/01-hash-tables/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "hash-tables-practice", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "hash-table.js", 6 | "scripts": { 7 | "test": "mocha" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "chai": "^4.3.4", 13 | "js-sha256": "^0.9.0", 14 | "mocha": "^8.3.2" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /week-5/d1-big-o-arrays/extra-practice/big-o-intro-extra-practice/02-anagrams.js: -------------------------------------------------------------------------------- 1 | function firstAnagram(str1, str2) { 2 | // Code goes here .... 3 | } 4 | 5 | 6 | 7 | function secondAnagram(str1, str2) { 8 | // Code goes here .... 9 | } 10 | 11 | 12 | function thirdAnagram(str1, str2) { 13 | // Code goes here .... 14 | } 15 | 16 | 17 | function fourthAnagram(str1, str2) { 18 | // Code goes here .... 19 | } 20 | -------------------------------------------------------------------------------- /week-4/d3-context-bind-call-apply/practices/04-context-arrow-functions/index.js: -------------------------------------------------------------------------------- 1 | const User = require('./classes/user'); 2 | 3 | const michelle = new User('Michelle'); 4 | 5 | function greetAfterNameChange(changeName, newName) { 6 | const name = changeName(newName); 7 | 8 | console.log(`Hi my name is ${name}`); 9 | } 10 | 11 | greetAfterNameChange(michelle.changeName, 'Elle'); 12 | // should print out: Hi my name is Elle -------------------------------------------------------------------------------- /week-5/w5-long-practice-solutions/w5-long-practice-solutions.md: -------------------------------------------------------------------------------- 1 | ## Week 5 Long Practice Solutions 2 | 3 | ### These solutions will be added by the EOD the day of each long practice. 4 | 5 | - D1 6 | - Array Problems Long Practice 7 | - D2 8 | - Binary Logic Long Practice 9 | - Dynamic Arrays Long Practice 10 | - D3 11 | - Linked Lists and Queues Long Practice 12 | - D4 13 | - Hash Tables Long Practice 14 | -------------------------------------------------------------------------------- /week-4/d4-test-driven-development/practices/02-unit-testing/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "unit-testing-practice", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "mocha" 8 | }, 9 | "keywords": [], 10 | "author": "", 11 | "license": "ISC", 12 | "dependencies": { 13 | "chai": "^4.3.4", 14 | "chai-spies": "^1.0.0", 15 | "mocha": "^9.0.0" 16 | } 17 | } -------------------------------------------------------------------------------- /week-6/d3-binary-search-trees/practices/01-binary-search-trees/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "binary-search-tree-practice", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "binary-search-tree.js", 6 | "scripts": { 7 | "test": "mocha" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "chai": "^4.3.4", 13 | "chai-spies": "^1.0.0", 14 | "mocha": "^8.3.2" 15 | } 16 | } -------------------------------------------------------------------------------- /week-5/d1-big-o-arrays/practices/01-timing-benchmarks/phase-2.js: -------------------------------------------------------------------------------- 1 | const [addNums, addManyNums] = require("./phase-1"); 2 | 3 | // Runs `addNums` in 10 increasing increments 4 | function addNums10(increment) { 5 | // Fill this in 6 | 7 | 8 | } 9 | 10 | // Runs `addManyNums` in 10 increasing increments 11 | function addManyNums10(increment) { 12 | // Fill this in 13 | 14 | 15 | } 16 | 17 | module.exports = [addNums10, addManyNums10]; 18 | -------------------------------------------------------------------------------- /week-4/d3-context-bind-call-apply/practices/03-call-apply/classes/gradebook.js: -------------------------------------------------------------------------------- 1 | class GradeBook { 2 | constructor(gradeList) { 3 | this.gradeList = gradeList; 4 | } 5 | 6 | getAverage(bonus = 0) { 7 | let sum = 0; 8 | let graded = 0; 9 | this.gradeList.forEach((grade) => { 10 | sum += grade; 11 | graded++; 12 | }); 13 | 14 | return sum / graded + bonus; 15 | } 16 | } 17 | 18 | module.exports = GradeBook; 19 | -------------------------------------------------------------------------------- /week-4/d2-es6-classes/notes/demo.js: -------------------------------------------------------------------------------- 1 | //accessing methods on a grandparent class: 2 | 3 | class GrandParent { 4 | funcA() { 5 | console.log("GrandParent"); 6 | } 7 | } 8 | class Parent extends GrandParent { 9 | funcA() { 10 | console.log("Parent"); 11 | super.funcA(); 12 | } 13 | } 14 | class Child extends Parent { 15 | funcA() { 16 | console.log("Child"); 17 | super.funcA(); 18 | } 19 | } 20 | 21 | const x = new Child(); 22 | x.funcA(); -------------------------------------------------------------------------------- /week-5/d2-binary-hexa-ascii-memory-arrays/notes/logic-and-truth.md: -------------------------------------------------------------------------------- 1 | # Key Logic and Truth Points: 2 | 3 | - ! = not 4 | - && = both conditions are true 5 | - || = one or both conditions are true 6 | - XOR ( ^ ) = exclusive or, one is true, but not both 7 | 8 | - True can be represented by 1, and false by 0. 9 | 10 | - De Morgan's Law: 11 | !(A && B) === !A || !B 12 | 13 | 14 | A | B XOR 15 | ----- 16 | T | T => F 17 | T | F => T 18 | F | T => T 19 | F | F => F -------------------------------------------------------------------------------- /week-4/d5-es5-class-syntax/practices/01-custom-error-types/error-types/maximum-length-exceeded-error.js: -------------------------------------------------------------------------------- 1 | const ValidationError = require('./validation-error'); 2 | 3 | // Your code here 4 | 5 | /****************************************************************************/ 6 | /******************* DO NOT EDIT CODE BELOW THIS LINE ***********************/ 7 | 8 | try { 9 | module.exports = MaximumLengthExceededError; 10 | } catch { 11 | module.exports = null; 12 | } 13 | -------------------------------------------------------------------------------- /week-4/d2-es6-classes/practices/03-inheritance/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "inheritance-practice", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "directories": { 7 | "test": "test" 8 | }, 9 | "scripts": { 10 | "test": "mocha" 11 | }, 12 | "keywords": [], 13 | "author": "", 14 | "license": "ISC", 15 | "dependencies": { 16 | "chai": "^4.3.4", 17 | "chai-spies": "^1.0.0", 18 | "mocha": "^9.0.0" 19 | } 20 | } -------------------------------------------------------------------------------- /week-4/d2-es6-classes/practices/04-polymorphism/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "polymorphism-practice", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "directories": { 7 | "test": "test" 8 | }, 9 | "scripts": { 10 | "test": "mocha" 11 | }, 12 | "keywords": [], 13 | "author": "", 14 | "license": "ISC", 15 | "dependencies": { 16 | "chai": "^4.3.4", 17 | "chai-spies": "^1.0.0", 18 | "mocha": "^9.0.0" 19 | } 20 | } -------------------------------------------------------------------------------- /week-4/d5-es5-class-syntax/practices/02-es5-classes/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "es5-classes", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "directories": { 7 | "test": "test" 8 | }, 9 | "scripts": { 10 | "test": "mocha" 11 | }, 12 | "keywords": [], 13 | "author": "", 14 | "license": "ISC", 15 | "dependencies": { 16 | "chai": "^4.3.4", 17 | "chai-spies": "^1.0.0", 18 | "mocha": "^9.0.3" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /week-4/d1-basic-coding-principles/practices/01-reading-tests-exercise/README.md: -------------------------------------------------------------------------------- 1 | # Exercise: Reading Tests 2 | 3 | In this exercise, you will deduce what some given test specs are testing for. 4 | 5 | ## Set Up 6 | 7 | Clone the exercise from the [starter]. 8 | 9 | ## Instructions 10 | 11 | Take a look at the __test/specs.js__ file provided to you. Deduce what the file 12 | is testing. 13 | 14 | [starter]: https://github.com/appacademy/practice-for-week-04-reading-tests-exercise -------------------------------------------------------------------------------- /week-4/d2-es6-classes/practices/02-basic-class-syntax/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "class-syntax-practice", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "directories": { 7 | "test": "test" 8 | }, 9 | "scripts": { 10 | "test": "mocha" 11 | }, 12 | "keywords": [], 13 | "author": "", 14 | "license": "ISC", 15 | "dependencies": { 16 | "chai": "^4.3.4", 17 | "chai-spies": "^1.0.0", 18 | "mocha": "^9.0.0" 19 | } 20 | } -------------------------------------------------------------------------------- /week-4/d2-es6-classes/notes/classes-commonJS-modules/accounting.js: -------------------------------------------------------------------------------- 1 | class Invoice { 2 | constructor(invoiceNumber, client) { 3 | this.invoiceNumber = invoiceNumber; 4 | this.client = client; 5 | } 6 | 7 | getClientName() { 8 | return this.client.name; 9 | } 10 | } 11 | class Receipt { 12 | constructor(receiptNum, date) { 13 | this.receiptNum = receiptNum; 14 | this.date = date 15 | } 16 | } 17 | 18 | 19 | module.exports = { 20 | Invoice, Receipt 21 | }; 22 | -------------------------------------------------------------------------------- /week-4/d5-es5-class-syntax/practices/01-custom-error-types/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "custom-error-types", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "directories": { 7 | "test": "test" 8 | }, 9 | "scripts": { 10 | "test": "mocha" 11 | }, 12 | "keywords": [], 13 | "author": "", 14 | "license": "ISC", 15 | "dependencies": { 16 | "chai": "^4.3.4", 17 | "chai-spies": "^1.0.0", 18 | "mocha": "^9.0.3" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /week-5/d1-big-o-arrays/extra-practice/big-o-intro-extra-practice/04-execution-time-differences.js: -------------------------------------------------------------------------------- 1 | function myMin1a(list) { 2 | // Code goes here ... 3 | } 4 | 5 | 6 | function myMin1b(list) { 7 | // Code goes here ... 8 | } 9 | 10 | 11 | function myMin2(list) { 12 | // Code goes here ... 13 | } 14 | 15 | 16 | function largestContiguousSubsum1(array) { 17 | // Code goes here ... 18 | } 19 | 20 | 21 | function largestContiguousSubsum2(array) { 22 | // Code goes here ... 23 | } 24 | -------------------------------------------------------------------------------- /week-4/d5-es5-class-syntax/practices/02-es5-classes/classes/dog.js: -------------------------------------------------------------------------------- 1 | class Dog { 2 | constructor(name, age) { 3 | this.name = name; 4 | this.age = age; 5 | } 6 | 7 | bark() { 8 | console.log("Bark"); 9 | } 10 | 11 | static diet() { 12 | return "carnivore"; 13 | } 14 | } 15 | 16 | /****************************************************************************/ 17 | /******************* DO NOT EDIT CODE BELOW THIS LINE ***********************/ 18 | 19 | module.exports = Dog; 20 | -------------------------------------------------------------------------------- /week-5/d1-big-o-arrays/extra-practice/big-o-intro-extra-practice/03-two-sum.js: -------------------------------------------------------------------------------- 1 | function badTwoSum(arr, targetSum) { 2 | // Code goes here ... 3 | } 4 | 5 | 6 | function okayTwoSum1(arr, targetSum) { 7 | // Code goes here ... 8 | } 9 | 10 | 11 | function okayTwoSum2(arr, targetSum) { 12 | // Code goes here ... 13 | } 14 | 15 | 16 | function twoSum(arr, targetSum) { 17 | // Code goes here ... 18 | } 19 | 20 | 21 | function twoSumIndices(arr, targetSum) { 22 | // Code goes here ... 23 | } 24 | -------------------------------------------------------------------------------- /week-5/d1-big-o-arrays/notes/demo.js: -------------------------------------------------------------------------------- 1 | function one(arr) { 2 | for (let i = 0; i < arr.length; i++) { 3 | console.log(arr[i]); 4 | } 5 | } 6 | 7 | function two(arr) { 8 | for (let i = 0; i < arr.length; i++) { 9 | for (let j = 1; j < arr.length; j++) { 10 | console.log([i, j]); 11 | } 12 | } 13 | } 14 | 15 | function three(arr) { 16 | for (let i = 0; i < arr.length; i++) { 17 | console.log(arr[i]); 18 | } 19 | arr.forEach((ele) => { 20 | ele *= 2; 21 | }); 22 | } 23 | -------------------------------------------------------------------------------- /week-6/d3-binary-search-trees/key-takeaways.md: -------------------------------------------------------------------------------- 1 | # Be able to: 2 | - Identify and describe a binary tree. 3 | - Identify and describe a binary search tree, and explain what makes it a true BST. 4 | - Identify a balanced and unbalanced tree. 5 | - Identify, demonstrate and describe the following: 6 | - Pre-order, in-order and post-order traversals 7 | - Breadth first traversal 8 | - Depth first traversal 9 | - Implement a BST along with search, insert, delete methods, as well as any traversals. 10 | -------------------------------------------------------------------------------- /week-6/d2-binary-search-merge-quicksort/practices/02-merge-sort/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "advanced-sort", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "quick-sort.js", 6 | "directories": { 7 | "test": "test" 8 | }, 9 | "scripts": { 10 | "test": "mocha" 11 | }, 12 | "keywords": [ 13 | "a" 14 | ], 15 | "author": "", 16 | "license": "ISC", 17 | "dependencies": { 18 | "chai": "^4.3.4", 19 | "chai-spies": "^1.0.0", 20 | "mocha": "^8.3.2" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /week-6/d2-binary-search-merge-quicksort/practices/03-quicksort/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "advanced-sort", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "quick-sort.js", 6 | "directories": { 7 | "test": "test" 8 | }, 9 | "scripts": { 10 | "test": "mocha" 11 | }, 12 | "keywords": [ 13 | "a" 14 | ], 15 | "author": "", 16 | "license": "ISC", 17 | "dependencies": { 18 | "chai": "^4.3.4", 19 | "chai-spies": "^1.0.0", 20 | "mocha": "^8.3.2" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /week-4/d4-test-driven-development/key-takeaways.md: -------------------------------------------------------------------------------- 1 | # Be able to: 2 | - Describe various types of Errors and what causes them (Syntax, Reference, Type). 3 | - Throw an error. 4 | - Utilize try-catch blocks to test functionality of your code. 5 | - Read and write unit tests in Mocha/chai using describe, it, context, beforeEach hook. 6 | - Remember the three As: Arrange, Act, Assert of unit testing. 7 | - Remember Red-Green-Refactor. 8 | - Describe the three parts of testing: unit testing, integration testing, end to end testing. 9 | -------------------------------------------------------------------------------- /week-6/d2-binary-search-merge-quicksort/practices/01-binary-search/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "search-sort", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "binary-search.js", 6 | "directories": { 7 | "test": "test" 8 | }, 9 | "scripts": { 10 | "test": "mocha" 11 | }, 12 | "keywords": [ 13 | "a" 14 | ], 15 | "author": "", 16 | "license": "ISC", 17 | "dependencies": { 18 | "chai": "^4.3.4", 19 | "chai-spies": "^1.0.0", 20 | "mocha": "^8.3.2" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /week-4/d2-es6-classes/key-takeaways.md: -------------------------------------------------------------------------------- 1 | # Be able to: 2 | - Import and export objects to and from different modules. 3 | - Implement a JS class with static and instance methods. 4 | - Implement a constructor method for a class. 5 | - Call instance methods for one class inside of instance methods for other classes. 6 | - Call static methods on a class passing in instances of that class. 7 | - Key into methods and properties of an object when working with instances of a class. 8 | - Identify and demonstrate inheritance and polymorphism. 9 | -------------------------------------------------------------------------------- /week-5/d2-binary-hexa-ascii-memory-arrays/practices/01-binary-hexa-conversion-functions/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "binary-hexa-conversion-functions", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "binary-hexa-conversion-functions.js", 6 | "directories": { 7 | "test": "test" 8 | }, 9 | "scripts": { 10 | "test": "mocha" 11 | }, 12 | "keywords": [], 13 | "author": "", 14 | "license": "ISC", 15 | "dependencies": { 16 | "chai": "^4.3.6", 17 | "mocha": "^9.2.2" 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /week-6/d1-sorting-bubble-insertion-selection/practices/01-bubble-sort/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "search-sort", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "binary-search.js", 6 | "directories": { 7 | "test": "test" 8 | }, 9 | "scripts": { 10 | "test": "mocha" 11 | }, 12 | "keywords": [ 13 | "a" 14 | ], 15 | "author": "", 16 | "license": "ISC", 17 | "dependencies": { 18 | "chai": "^4.3.4", 19 | "chai-spies": "^1.0.0", 20 | "mocha": "^8.3.2" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /week-6/d1-sorting-bubble-insertion-selection/practices/02-insertion-sort/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "search-sort", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "binary-search.js", 6 | "directories": { 7 | "test": "test" 8 | }, 9 | "scripts": { 10 | "test": "mocha" 11 | }, 12 | "keywords": [ 13 | "a" 14 | ], 15 | "author": "", 16 | "license": "ISC", 17 | "dependencies": { 18 | "chai": "^4.3.4", 19 | "chai-spies": "^1.0.0", 20 | "mocha": "^8.3.2" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /week-6/d1-sorting-bubble-insertion-selection/practices/03-selection-sort/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "search-sort", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "binary-search.js", 6 | "directories": { 7 | "test": "test" 8 | }, 9 | "scripts": { 10 | "test": "mocha" 11 | }, 12 | "keywords": [ 13 | "a" 14 | ], 15 | "author": "", 16 | "license": "ISC", 17 | "dependencies": { 18 | "chai": "^4.3.4", 19 | "chai-spies": "^1.0.0", 20 | "mocha": "^8.3.2" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /week-5/d2-binary-hexa-ascii-memory-arrays/practices/02-ascii-advanced-conversion-functions/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ascii-advanced-conversion-functions", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "ascii-advanced-conversion-functions.js", 6 | "directories": { 7 | "test": "test" 8 | }, 9 | "scripts": { 10 | "test": "mocha" 11 | }, 12 | "keywords": [], 13 | "author": "", 14 | "license": "ISC", 15 | "dependencies": { 16 | "chai": "^4.3.6", 17 | "mocha": "^9.2.2" 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /week-4/d3-context-bind-call-apply/practices/03-call-apply/grade.js: -------------------------------------------------------------------------------- 1 | // Do not modify! 2 | const GradeBook = require('./classes/gradebook.js'); 3 | const grades = new GradeBook([100, 50, 90, 20, 30]); 4 | const gradesAvg = grades.getAverage; 5 | 6 | // You can modify the following lines 7 | let grades1Average = gradesAvg(grades); 8 | let grades1WithBonus = gradesAvg(grades, [20]); 9 | 10 | console.log('Grade list'); 11 | console.log(grades1Average); // should print out: 58 12 | console.log(grades1WithBonus); // should print out: 78 13 | -------------------------------------------------------------------------------- /week-6/d1-sorting-bubble-insertion-selection/practices/01-bubble-sort/bubble-sort.js: -------------------------------------------------------------------------------- 1 | 2 | function bubbleSort(arr) { 3 | 4 | // Iterate through the array 5 | 6 | // If the current value is greater than its neighbor to the right 7 | // Swap those values 8 | 9 | // Do not move this console.log 10 | console.log(arr.join(",")); 11 | 12 | // If you get to the end of the array and no swaps have occurred, return 13 | 14 | // Otherwise, repeat from the beginning 15 | 16 | } 17 | 18 | module.exports = bubbleSort; 19 | -------------------------------------------------------------------------------- /week-4/d4-test-driven-development/practices/01-error-handling/error-handling.js: -------------------------------------------------------------------------------- 1 | // 1. 2 | function sum(array) { 3 | let sum = 0; 4 | for (let i = 0; i < array.length; i++) { 5 | sum += array[i]; 6 | } 7 | return sum; 8 | } 9 | 10 | let res = sum(null); 11 | console.log(res); 12 | 13 | // 2. 14 | // tests 15 | sayName("Alex"); 16 | sayName(1); 17 | // Your code here 18 | 19 | // 3. 20 | function greet(greeting) { 21 | if (!greeting) { 22 | throw new Error("There was no greeting given."); 23 | } 24 | 25 | console.log(greeting); 26 | } 27 | -------------------------------------------------------------------------------- /week-6/d4-graphs/practices/01-graph-repl-problems/morning-practice/06-degress-of-separation-bfs.js: -------------------------------------------------------------------------------- 1 | const adjList = { 2 | 1: [2, 5], 3 | 2: [1, 3, 5], 4 | 3: [2, 4], 5 | 4: [3, 5], 6 | 5: [1, 2, 4], 7 | 6: [] 8 | } 9 | 10 | function degreesOfSeparation(start, end) { 11 | // Your code here 12 | } 13 | 14 | console.log("First Test:"); 15 | console.log(degreesOfSeparation(1, 3)); // -> 2 16 | console.log("Second Test:"); 17 | console.log(degreesOfSeparation(5, 2)); // -> 1 18 | console.log("Third Test:"); 19 | console.log(degreesOfSeparation(6, 1)); // -> false 20 | -------------------------------------------------------------------------------- /week-6/d4-graphs/practices/01-graph-repl-problems/morning-practice/04-simple-breadth-first-search.js: -------------------------------------------------------------------------------- 1 | const adjList = { 2 | 1: [2, 5], 3 | 2: [1, 3, 5], 4 | 3: [2, 4], 5 | 4: [3, 5], 6 | 5: [1, 2, 4], 7 | 6: [] 8 | } 9 | 10 | function breadthFirstSearch(start, end) { 11 | // Your code here 12 | } 13 | 14 | console.log("First Test:"); 15 | console.log(breadthFirstSearch(1, 3)); // -> true 16 | console.log("Second Test:"); 17 | console.log(breadthFirstSearch(4, 1)); // -> true 18 | console.log("Third Test:"); 19 | console.log(breadthFirstSearch(6, 1)); // -> false 20 | -------------------------------------------------------------------------------- /week-4/d1-basic-coding-principles/practices/02-single-responsibility-principle/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "single-responsibility-principle", 3 | "version": "1.0.0", 4 | "description": "practice with Single Responsibility Principle", 5 | "main": "practice.js", 6 | "directories": { 7 | "test": "test" 8 | }, 9 | "dependencies": { 10 | "chai": "^4.3.4", 11 | "chai-spies": "^1.0.0", 12 | "mocha": "^9.0.3" 13 | }, 14 | "devDependencies": {}, 15 | "scripts": { 16 | "test": "mocha" 17 | }, 18 | "keywords": [], 19 | "author": "", 20 | "license": "ISC" 21 | } -------------------------------------------------------------------------------- /week-4/d3-context-bind-call-apply/practices/01-context-regular-functions/README.md: -------------------------------------------------------------------------------- 1 | # Exercise: Context with Regular Functions 2 | 3 | In this exercise, you will explore the context of a regular function. 4 | 5 | ## Set up 6 | 7 | Clone the starter from the **Download** link at the bottom of this page. 8 | 9 | ## Instructions 10 | 11 | For each scenario listed in the __context.js__ file, predict what will happen 12 | when the code is run. Then uncomment the code in the scenario and run the 13 | __context.js__ file, `node context.js`, to compare what actually happened to 14 | what you expected to happen. -------------------------------------------------------------------------------- /week-6/d4-graphs/practices/01-graph-repl-problems/morning-practice/05-a-shortest-path-bfs.js: -------------------------------------------------------------------------------- 1 | const adjList = { 2 | 1: [2, 5], 3 | 2: [1, 3, 5], 4 | 3: [2, 4], 5 | 4: [3, 5], 6 | 5: [1, 2, 4], 7 | 6: [] 8 | } 9 | 10 | function aShortestPath(start, end) { 11 | // Your code here 12 | } 13 | 14 | console.log("First Test:"); 15 | console.log(aShortestPath(1, 3)); // -> [ 1, 2, 3 ] (One possible solution) 16 | console.log("Second Test:"); 17 | console.log(aShortestPath(4, 1)); // -> [ 4, 5, 1 ] (One possible solution) 18 | console.log("Third Test:"); 19 | console.log(aShortestPath(6, 1)); // -> false 20 | -------------------------------------------------------------------------------- /week-4/d2-es6-classes/notes/import-export/adding.js: -------------------------------------------------------------------------------- 1 | exports.adding = function adding(a, b) { 2 | return a + b; 3 | } 4 | exports.subtraction = function subtraction(a, b) { 5 | if (a > b) return a - b; 6 | return b - a; 7 | } 8 | exports.division = (num1, num2) => { 9 | return num1 / num2; 10 | } 11 | //this function returns the sum of two numbers 12 | // module.exports = { 13 | // adding, subtraction, division 14 | // } 15 | // module.exports = { 16 | // adding: adding 17 | // } 18 | 19 | 20 | // module.exports.adding = adding 21 | //module.exports.subtraction = subtraction; 22 | 23 | console.log(module) -------------------------------------------------------------------------------- /week-4/d4-test-driven-development/notes/demo.js: -------------------------------------------------------------------------------- 1 | // funtion add(num1, num2){ 2 | // console.log(num1 + num2) 3 | // } 4 | 5 | // add(1, 2) 6 | 7 | // const puppy = "puppy"; 8 | // console.log(pupppy); 9 | 10 | // function sumDiv(n1, n2) { 11 | 12 | 13 | // } 14 | 15 | // console.log(sumDiv()) 16 | 17 | function funStuff(str) { 18 | const arr = str.split('') 19 | return arr; 20 | } 21 | 22 | try { 23 | funStuff(4) 24 | } catch (err) { 25 | console.log(err.message) 26 | // throw new Error('what are you doing?') 27 | } 28 | 29 | const taco = new Array(4).fill(null) 30 | console.log(taco) -------------------------------------------------------------------------------- /week-6/d2-binary-search-merge-quicksort/practices/03-quicksort/quicksort.js: -------------------------------------------------------------------------------- 1 | function quicksort(arr) { 2 | 3 | // Check if the input is length 1 or less 4 | // If so, it's already sorted: return 5 | 6 | // Pick the first value as the pivot 7 | 8 | // Orient the pivot so that... 9 | // every number smaller than the pivot is to the left 10 | // every number larger (or equal) than the pivot is to the right 11 | 12 | // Recursively sort the left 13 | // Recursively sort the right 14 | 15 | // Return the left, pivot and right in sorted order 16 | 17 | } 18 | 19 | 20 | module.exports = [quicksort]; 21 | -------------------------------------------------------------------------------- /week-5/d3-linked-lists-and-queues/practices/01-linked-lists/README-phase-1.md: -------------------------------------------------------------------------------- 1 | # Practice Linked Lists Phase 1 - Singly Linked List 2 | 3 | In this phase, your task is to implement the constructor, `addToHead` and 4 | `addToTail` functions for a singly linked list. 5 | 6 | ## Directions 7 | 8 | Start by implementing the most basic linked list that can `addToHead` and 9 | `addToTail`. It should only have a `head` pointer, no `tail` pointer. 10 | 11 | Read the test specs in **test/linked-list-practice-specs.js** for details. 12 | 13 | Add your code to **linked-list.js**. 14 | 15 | Run tests with `npm test test/linked-list-practice-specs.js` 16 | 17 | Read test specs for implementation requirements and details. -------------------------------------------------------------------------------- /week-5/d2-binary-hexa-ascii-memory-arrays/notes/arrays.md: -------------------------------------------------------------------------------- 1 | # Arrays 2 | 3 | - Arrays are the most time and space efficient way to store data 4 | 5 | Definition: An array is a sequence of elements of the same type, stored in a contiguous block of memory 6 | 7 | Indexing formula (under the hood of .indexOf()): valueAddress = startAddress + index \* sizeof(dataType) 8 | 9 | \*\* All three parts of this definition are required for O(1) indexing equation. 10 | 11 | The reason that JavaScript arrays allow for different types is because they are 12 | actually hash tables (we'll get to those soon). 13 | They contain a sequence of pointers (memory addresses) and each element's type is interpreted at runtime. 14 | 15 | 16 | -------------------------------------------------------------------------------- /week-5/d3-linked-lists-and-queues/practices/01-linked-lists/README-phase-3.md: -------------------------------------------------------------------------------- 1 | # Practice Linked Lists Phase 3 - Comparing performance 2 | 3 | In this phase, your task is to compare the performance between a singly and 4 | doubly linked lists which you implemented in phases 1 and 2. 5 | 6 | Continue working in same the [starter] repo as phases 1 and 2. 7 | 8 | ## Directions 9 | 10 | Identify the time complexity of `addToHead` and `addToTail` for both the 11 | single and doubly linked lists. 12 | 13 | Construct a timing test in **linked-list-timing.js** to verify your hypothesis. 14 | 15 | There are no test specs for this phase. 16 | 17 | [starter]: https://github.com/appacademy/practice-for-week-05-linked-list-practice -------------------------------------------------------------------------------- /week-6/d4-graphs/practices/02-social-graph-practice/social.js: -------------------------------------------------------------------------------- 1 | // Implement the SocialNetwork class here 2 | class SocialNetwork { 3 | 4 | constructor() { 5 | this.users = {}; 6 | this.follows = {}; 7 | this.currentID = 0; 8 | } 9 | 10 | addUser(name) { 11 | // Your code here 12 | } 13 | 14 | getUser(userID) { 15 | // Your code here 16 | } 17 | 18 | follow(userID1, userID2) { 19 | // Your code here 20 | } 21 | 22 | getFollows(userID) { 23 | // Your code here 24 | } 25 | 26 | getFollowers(userID) { 27 | // Your code here 28 | } 29 | 30 | getRecommendedFollows(userID, degrees) { 31 | // Your code here 32 | } 33 | } 34 | 35 | module.exports = SocialNetwork; 36 | -------------------------------------------------------------------------------- /week-5/d3-linked-lists-and-queues/practices/01-linked-lists/linked-list.js: -------------------------------------------------------------------------------- 1 | class LinkedListNode { 2 | constructor(val) { 3 | this.value = val; 4 | this.next = null; 5 | } 6 | } 7 | 8 | class LinkedList { 9 | constructor() { 10 | // Your code here 11 | } 12 | 13 | addToHead(val) { 14 | // Your code here 15 | } 16 | 17 | addToTail(val) { 18 | // Your code here 19 | } 20 | 21 | // You can use this function to help debug 22 | print() { 23 | let current = this.head; 24 | 25 | while (current) { 26 | process.stdout.write(`${current.value} -> `); 27 | current = current.next; 28 | } 29 | 30 | console.log("NULL"); 31 | } 32 | } 33 | 34 | module.exports = LinkedList; 35 | -------------------------------------------------------------------------------- /week-4/d5-es5-class-syntax/practices/02-es5-classes/classes/person.js: -------------------------------------------------------------------------------- 1 | const Dog = require('./dog'); 2 | 3 | class Person { 4 | constructor(name, age, dogs = []) { 5 | this.name = name; 6 | this.age = age; 7 | this.dogs = dogs; 8 | } 9 | 10 | addDog(dog) { 11 | if (!(dog instanceof Dog)) { 12 | throw new TypeError("Can only add dogs!"); 13 | } 14 | this.dogs.push(dog); 15 | } 16 | 17 | walkDogs() { 18 | this.dogs.forEach((dog) => { 19 | console.log(`walking ${dog.name}`); 20 | }); 21 | } 22 | } 23 | 24 | /****************************************************************************/ 25 | /******************* DO NOT EDIT CODE BELOW THIS LINE ***********************/ 26 | 27 | module.exports = Person; 28 | -------------------------------------------------------------------------------- /week-5/d3-linked-lists-and-queues/practices/01-linked-lists/doubly-linked-list.js: -------------------------------------------------------------------------------- 1 | class DoublyLinkedListNode { 2 | constructor(val) { 3 | this.value = val; 4 | this.prev = null; 5 | this.next = null; 6 | } 7 | } 8 | 9 | class DoublyLinkedList { 10 | constructor() { 11 | // Your code here 12 | } 13 | 14 | addToHead(val) { 15 | // Your code here 16 | } 17 | 18 | addToTail(val) { 19 | // Your code here 20 | } 21 | 22 | // You can use this function to help debug 23 | print() { 24 | let current = this.head; 25 | 26 | while (current) { 27 | process.stdout.write(`${current.value} <-> `); 28 | current = current.next; 29 | } 30 | 31 | console.log("NULL"); 32 | } 33 | } 34 | 35 | module.exports = DoublyLinkedList; 36 | -------------------------------------------------------------------------------- /week-5/d4-hash-tables-and-sets/practices/01-hash-tables/hash-table.js: -------------------------------------------------------------------------------- 1 | const sha256 = require('js-sha256'); 2 | 3 | class KeyValuePair { 4 | constructor(key, value) { 5 | this.key = key; 6 | this.value = value; 7 | this.next = null; 8 | } 9 | } 10 | 11 | class HashTable { 12 | 13 | constructor(numBuckets = 4) { 14 | // Your code here 15 | } 16 | 17 | hash(key) { 18 | // Your code here 19 | } 20 | 21 | hashMod(key) { 22 | // Your code here 23 | } 24 | 25 | insertNoCollisions(key, value) { 26 | // Your code here 27 | } 28 | 29 | insertWithHashCollisions(key, value) { 30 | // Your code here 31 | } 32 | 33 | insert(key, value) { 34 | // Your code here 35 | } 36 | 37 | } 38 | 39 | 40 | module.exports = HashTable; 41 | -------------------------------------------------------------------------------- /week-5/d3-linked-lists-and-queues/practices/01-linked-lists/README-phase-2.md: -------------------------------------------------------------------------------- 1 | # Practice Linked Lists Phase 2 - Doubly Linked List 2 | 3 | In this phase, your task is to implement the constructor, `addToHead` and 4 | `addToTail` functions for a doubly linked list. 5 | 6 | Continue working in same the [starter] repo as phase 1. 7 | 8 | ## Directions 9 | 10 | Next, implement the same `addToHead` and `addToTail` functions in a doubly 11 | linked list. It should have both a `head` and `tail` pointer. 12 | 13 | Add your code to **doubly-linked-list.js**. 14 | 15 | Run tests with `npm test test/doubly-linked-list-practice-specs.js` 16 | 17 | Read test specs for implementation requirements and details. 18 | 19 | [starter]: https://github.com/appacademy/practice-for-week-05-linked-list-practice -------------------------------------------------------------------------------- /week-5/d1-big-o-arrays/extra-practice/big-o-intro-extra-practice/01-big-octopus.js: -------------------------------------------------------------------------------- 1 | function quadraticBiggestFish(fishes) { 2 | // Code goes here ... 3 | } 4 | 5 | 6 | function nlognBiggestFish(fishes) { 7 | // Code goes here ... 8 | } 9 | 10 | 11 | function linearBiggestFish(fishes) { 12 | // Code goes here ... 13 | } 14 | 15 | 16 | tilesArray = ["up", "right-up", "right", "right-down", "down", "left-down", "left", "left-up"] 17 | function slowDance(direction, tilesArray) { 18 | // Code goes here ... 19 | } 20 | 21 | 22 | tilesObj = { 23 | "up": 0, 24 | "right-up": 1, 25 | "right": 2, 26 | "right-down": 3, 27 | "down": 4, 28 | "left-down": 5, 29 | "left": 6, 30 | "left-up": 7 31 | } 32 | function fastDance(direction, tilesObj) { 33 | // Code goes here ... 34 | } 35 | -------------------------------------------------------------------------------- /week-5/d3-linked-lists-and-queues/practices/01-linked-lists/README.md: -------------------------------------------------------------------------------- 1 | # Practice Linked Lists 2 | 3 | Your task is to implement the constructor, `addToHead` and `addToTail` function 4 | for a `LinkedList` and a `DoublyLinkedList`. 5 | 6 | Read the specs for details. 7 | 8 | ## Instructions 9 | 10 | 1. Clone the [starter] repo 11 | 2. Install all packages by typing `npm install` 12 | 3. Read through the test specs to understand the task 13 | 4. Run specs with `npm test` 14 | 15 | ## Phases 16 | 17 | 1. Singly Linked List - implement the most basic linked list 18 | 2. Doubly Linked List - implement a more complex linked list 19 | 3. Comparing performance - compare the performance between a singly and doubly 20 | linked lists 21 | 22 | [starter]: https://github.com/appacademy/practice-for-week-05-linked-list-practice -------------------------------------------------------------------------------- /week-4/d2-es6-classes/practices/04-polymorphism/classes/teacher.js: -------------------------------------------------------------------------------- 1 | const Person = require('./person'); 2 | 3 | class Teacher extends Person { 4 | constructor(firstName, lastName, subject, yearsOfExperience) { 5 | super(firstName, lastName); 6 | this.subject = subject; 7 | this.yearsOfExperience = yearsOfExperience; 8 | } 9 | 10 | static combinedYearsOfExperience(teachers) { 11 | let count = 0; 12 | for (const teacher of teachers) { 13 | count += teacher.yearsOfExperience; 14 | } 15 | return count; 16 | } 17 | } 18 | 19 | /****************************************************************************/ 20 | /******************* DO NOT EDIT CODE BELOW THIS LINE ***********************/ 21 | 22 | try { 23 | module.exports = Teacher; 24 | } catch { 25 | module.exports = null; 26 | } 27 | -------------------------------------------------------------------------------- /week-4/d5-es5-class-syntax/notes/es5-syntax.js: -------------------------------------------------------------------------------- 1 | function Cat(name) { 2 | this.name = name; 3 | } 4 | let myCat = new Cat("Chatty"); 5 | 6 | Cat.prototype.sayHello = function () { 7 | console.log(`my name is ${this.name}`); 8 | }; 9 | 10 | Cat.prototype.changeName = function (newName) { 11 | this.name = newName; 12 | this.sayHello(); 13 | }; 14 | 15 | myCat.sayHello(); // my name is Chatty 16 | myCat.changeName("Midnight"); // my name is Midnight 17 | 18 | // console.log(myCat); // Cat { name: 'Midnight' } 19 | 20 | console.log(Cat.prototype); 21 | 22 | function Unicorn(name, age, color, power) { 23 | this.name = name; 24 | this.age = age; 25 | this.color = color; 26 | this.power = power; 27 | } 28 | 29 | let sparkleButt = new Unicorn("sparkleButt", 3, "pink", "invisibility"); 30 | console.log(sparkleButt); 31 | console.log(Unicorn); 32 | -------------------------------------------------------------------------------- /week-6/d4-graphs/practices/01-graph-repl-problems/homework/02-simple-depth-first-traversal.js: -------------------------------------------------------------------------------- 1 | const adjList = { 2 | 1: [2, 5], 3 | 2: [1, 3, 5], 4 | 3: [2, 4], 5 | 4: [3, 5, 6], 6 | 5: [1, 2, 4], 7 | 6: [4] 8 | } 9 | 10 | function printDepthFirst(start) { 11 | // your code here 12 | } 13 | 14 | console.log("First Test:") 15 | printDepthFirst(3); // Prints 1 through 6 in Breadth-first order, starting with 3 16 | // One possible solution: 3, 4, 6, 5, 1, 2 17 | console.log("Second Test:") 18 | printDepthFirst(6); // Prints 1 through 6 in Breadth-first order, starting with 6 19 | // One possible solution: 6, 4, 5, 2, 1, 3 20 | console.log("Third Test:") 21 | printDepthFirst(4); // Prints 1 through 6 in Breadth-first order, starting with 4 22 | // One possible solution: 4, 6, 5, 2, 1, 3 23 | -------------------------------------------------------------------------------- /week-6/d2-binary-search-merge-quicksort/practices/03-quicksort/test/quicksort-specs.js: -------------------------------------------------------------------------------- 1 | const { expect } = require('chai'); 2 | 3 | const chai = require('chai'); 4 | const spies = require('chai-spies'); 5 | 6 | chai.use(spies); 7 | 8 | const [quicksort] = require("../quicksort.js"); 9 | 10 | describe ('Better Sorting Algorithms', function () { 11 | 12 | let arr; 13 | let consoleSpy; 14 | 15 | beforeEach(function () { 16 | 17 | consoleSpy = chai.spy.on(console, 'log'); 18 | 19 | arr = [2,4,6,8,1,3,5,7,9]; 20 | }); 21 | 22 | afterEach(() => { 23 | chai.spy.restore(console, 'log'); 24 | }); 25 | 26 | it('performs a out-of-place quicksort', function () { 27 | 28 | let newArr = quicksort(arr); 29 | 30 | expect(newArr).to.deep.equal([1,2,3,4,5,6,7,8,9]); 31 | expect(arr).to.deep.equal([2,4,6,8,1,3,5,7,9]); 32 | 33 | }); 34 | 35 | }); 36 | 37 | -------------------------------------------------------------------------------- /week-6/d4-graphs/practices/01-graph-repl-problems/homework/01-simple-breadth-first-traversal.js: -------------------------------------------------------------------------------- 1 | const adjList = { 2 | 1: [2, 5], 3 | 2: [1, 3, 5], 4 | 3: [2, 4], 5 | 4: [3, 5, 6], 6 | 5: [1, 2, 4], 7 | 6: [4] 8 | } 9 | 10 | function printBreadthFirst(start) { 11 | // your code here 12 | } 13 | 14 | console.log("First Test:") 15 | printBreadthFirst(3); // Prints 1 through 6 in Breadth-first order, starting with 3 16 | // One possible solution: 3, 2, 4, 1, 5, 6 17 | console.log("Second Test:") 18 | printBreadthFirst(6); // Prints 1 through 6 in Breadth-first order, starting with 6 19 | // One possible solution: 6, 4, 3, 5, 2, 1 20 | console.log("Third Test:") 21 | printBreadthFirst(4); // Prints 1 through 6 in Breadth-first order, starting with 4 22 | // One possible solution: 4, 3, 5, 6, 2, 1 23 | -------------------------------------------------------------------------------- /week-6/d4-graphs/practices/01-graph-repl-problems/morning-practice/03-refactor-bft.js: -------------------------------------------------------------------------------- 1 | const adjList = { 2 | 1: [2, 5], 3 | 2: [1, 3, 5], 4 | 3: [2, 4], 5 | 4: [3, 5, 6], 6 | 5: [1, 2, 4], 7 | 6: [4] 8 | } 9 | 10 | function printBreadthFirst(start) { 11 | // Paste your previous code here and refactor it 12 | } 13 | 14 | console.log("First Test:") 15 | printBreadthFirst(3); // Prints 1 through 6 in Breadth-first order, starting with 3 16 | // One possible solution: [ 3, 2, 4, 1, 5, 6 ] 17 | console.log("Second Test:") 18 | printBreadthFirst(6); // Prints 1 through 6 in Breadth-first order, starting with 6 19 | // One possible solution: [ 6, 4, 3, 5, 2, 1 ] 20 | console.log("Third Test:") 21 | printBreadthFirst(4); // Prints 1 through 6 in Breadth-first order, starting with 4 22 | // One possible solution: [ 4, 3, 5, 6, 2, 1 ] 23 | -------------------------------------------------------------------------------- /week-4/d5-es5-class-syntax/practices/02-es5-classes/test/array-spec.js: -------------------------------------------------------------------------------- 1 | const chai = require("chai"); 2 | const expect = chai.expect; 3 | 4 | require('../classes/array'); 5 | 6 | describe("Array", () => { 7 | describe("isEqual(array)", () => { 8 | context("if each element on the array instance is equal to the passed-in array", () => { 9 | it("should return true", () => { 10 | expect([1, 2, 3].isEqual([1, 2, 3])).to.be.true; 11 | expect([1, 2, 3, 4].isEqual([1, 2, 3, 4])).to.be.true; 12 | }); 13 | }); 14 | context("if each element on the array instance is NOT equal to the passed-in array", () => { 15 | it("should return false", () => { 16 | expect([1, 2, 3].isEqual([3, 4, 5])).to.be.false; 17 | expect([1, 2, 3, 4].isEqual([10, 9, 8, 7])).to.be.false; 18 | expect([1, 2, 3, 4].isEqual([10, 9, 8])).to.be.false; 19 | }); 20 | }); 21 | }); 22 | }); 23 | -------------------------------------------------------------------------------- /week-6/d3-binary-search-trees/practices/01-binary-search-trees/README-pt2.md: -------------------------------------------------------------------------------- 1 | # Practice: Binary Search Tree - Part 2 2 | 3 | In this exercise, you will be implementing search in a basic binary search 4 | tree. 5 | 6 | ## Setup 7 | 8 | 1. Continue working from the same starter as part 1 9 | 2. Read the instructions and test specs to understand the problem 10 | 3. Fill out the code until tests are all green 11 | 12 | ## Part 2: Binary Search Tree search 13 | 14 | Now that you can build valid binary search trees, you can implement the 15 | `search` method. 16 | 17 | `search(val)` should return `true` if the value is in the tree and `false` if 18 | it is not. 19 | 20 | ```plaintext 21 | 4 22 | / \ 23 | 3 5 24 | ``` 25 | 26 | For example, in the tree pictured above, `bst.search(3)` would return `true` 27 | and `bst.search(6)` would return false. 28 | 29 | Read through the specs in `test/binary-search-tree-spec.js` for more details. -------------------------------------------------------------------------------- /week-6/d2-binary-search-merge-quicksort/practices/01-binary-search/binary-search.js: -------------------------------------------------------------------------------- 1 | function linearSearch (arr, target) { 2 | 3 | // Can you solve this in one line? 4 | 5 | }; 6 | 7 | function binarySearch(arr, target) { 8 | 9 | // Set integers pointing to the high and low range of possible indices 10 | 11 | // While high and low indices do not overlap... 12 | 13 | // Find the midpoint between high and low indices 14 | 15 | // Compare the target value to the midpoint value 16 | 17 | // If the target equals the midpoint... 18 | // Return the midpoint index 19 | // If the target is higher than the midpoint... 20 | // Move the low pointer to midpoint + 1 21 | // If the target is less than the midpoint... 22 | // Move the high pointer to midpoint - 1 23 | 24 | // Return -1 if the loop exits with overlapping pointers 25 | 26 | } 27 | 28 | 29 | module.exports = [linearSearch, binarySearch] 30 | -------------------------------------------------------------------------------- /week-4/d2-es6-classes/practices/04-polymorphism/classes/student.js: -------------------------------------------------------------------------------- 1 | const Person = require('./person'); 2 | 3 | class Student extends Person { 4 | constructor(firstName, lastName, major, GPA) { 5 | super(firstName, lastName); 6 | this.major = major; 7 | this.GPA = GPA; 8 | } 9 | 10 | static compareGPA(student1, student2) { 11 | if (student1.GPA > student2.GPA) { 12 | return `${student1.firstName} ${student1.lastName} has the higher GPA.`; 13 | } else if (student2.GPA > student1.GPA) { 14 | return `${student2.firstName} ${student2.lastName} has the higher GPA.`; 15 | } else { 16 | return "Both students have the same GPA"; 17 | } 18 | } 19 | } 20 | 21 | /****************************************************************************/ 22 | /******************* DO NOT EDIT CODE BELOW THIS LINE ***********************/ 23 | 24 | try { 25 | module.exports = Student; 26 | } catch { 27 | module.exports = null; 28 | } 29 | -------------------------------------------------------------------------------- /week-4/d1-basic-coding-principles/practices/02-single-responsibility-principle/README.md: -------------------------------------------------------------------------------- 1 | # Practice: Single Responsibility Principle 2 | 3 | In this practice, you will be refactoring code to follow the Single 4 | Responsibility Principle. 5 | 6 | ## Set Up 7 | 8 | Clone the practice from the [starter]. 9 | 10 | Run `npm install` to install all dependencies. 11 | 12 | ## Directions 13 | 14 | Take a look at the `bakeAndSellPies` function in the __practice.js__ file. This 15 | function passes all the specs if you run `npm test`, but the function is doing 16 | too much. Refactor the function into multiple helper functions to follow the 17 | Single-Responsibility Principle. 18 | 19 | When you are sure that you have successfully refactored the code, run `npm test` 20 | to see if the functions still return the correct information by making sure all 21 | the test specs still pass. 22 | 23 | [starter]: https://github.com/appacademy/practice-for-week-04-single-responsibility-principle -------------------------------------------------------------------------------- /week-4/d1-basic-coding-principles/practices/03-dry/README.md: -------------------------------------------------------------------------------- 1 | # Practice: Making Code DRY 2 | 3 | In this practice, you will use the DRY principle to abstract a pattern into a 4 | helper function. 5 | 6 | ## Set Up 7 | 8 | Clone the practice from the [starter]. 9 | 10 | Run `npm install` to install all dependencies. 11 | 12 | ## Directions 13 | 14 | You will find four functions in the file __practice.js__. If you run `npm test` 15 | now, you should see all the specs testing those four functions passing. Your job 16 | is to look at the four functions and identify where you may be able to refactor 17 | by creating a **single** helper function that is used in **all four** functions to help DRY 18 | this code. 19 | 20 | When you are sure that you have successfully refactored the code, run `npm test` 21 | to see if the functions still return the correct information by making sure all 22 | the test specs still pass. 23 | 24 | [starter]: https://github.com/appacademy/practice-for-week-04-DRY -------------------------------------------------------------------------------- /week-6/d2-binary-search-merge-quicksort/practices/02-merge-sort/merge-sort.js: -------------------------------------------------------------------------------- 1 | // Merge Sort out-of-place 2 | // Do not modify the original array 3 | function mergeSort(arr) { 4 | 5 | // Check if the input is length 1 or less 6 | // If so, it's already sorted: return 7 | 8 | // Divide the array in half 9 | 10 | // Recursively sort the left half 11 | // Recursively sort the right half 12 | 13 | // Merge the halves together and return 14 | 15 | } 16 | 17 | 18 | // Takes in two sorted arrays and returns them merged into one 19 | function merge(arrA, arrB) { 20 | 21 | // Create an empty return array 22 | 23 | // Point to the first value of each array 24 | // While there are still values in each array... 25 | // Compare the first values of each array 26 | // Add the smaller value to the return array 27 | // Move the pointer to the next value in that array 28 | 29 | // Return the return array 30 | 31 | } 32 | 33 | module.exports = [merge, mergeSort]; 34 | -------------------------------------------------------------------------------- /week-5/d1-big-o-arrays/practices/01-timing-benchmarks/README.md: -------------------------------------------------------------------------------- 1 | # Practice Timing Benchmarks 2 | 3 | In this three-phase exercise, you will be implementing a few simple JavaScript 4 | functions, then testing them at _massive_ scale. 5 | 6 | ## Goals 7 | 8 | * Practice for-loop fundamentals 9 | * Get comfortable with large _n_ values 10 | * Practice timing code with `Date.now()` and `console.time()` 11 | * Record and display timing results on a Google Sheet 12 | * Identify and prove that code is O(1), O(n) or O(n^2) 13 | 14 | ## Setup 15 | 16 | 1. Clone the starter repo at [starter] 17 | 2. Install all packages with `npm install` 18 | 19 | ## Phases 20 | 21 | 1. Implementation - Implement the code you will be testing in the other phases 22 | 2. Scale testing harness - Testing your code for a variety of inputs 23 | 3. Timing your code - Measure the time it takes to run with various input sizes 24 | 25 | [starter]: https://github.com/appacademy/practice-for-week-05-timing-benchmarks-practice 26 | -------------------------------------------------------------------------------- /week-5/d4-hash-tables-and-sets/practices/01-hash-tables/README-pt2.md: -------------------------------------------------------------------------------- 1 | # Hash Table Practice Part 2 2 | 3 | In this four-part exercise, you will start implementing a hash table that 4 | handles hash collisions with linked list chaining. 5 | 6 | ## Setup 7 | 8 | 1. Continue working in the same starter as part 1 9 | 2. Run specs with `npm test test/hash-table-pt2-spec.js` 10 | 11 | ## Hash table insert 12 | 13 | Next, you will use your hash function from part 1 to store a key/value pair in 14 | your hash table. This implementation will not handle hash collisions but focus 15 | on insertion at the bucket location. 16 | 17 | `insertNoCollisions(key, value)` will create a new `KeyValuePair()` with 18 | the input key and value and store it in the data bucket location returned by 19 | `hashMod(key)`. 20 | 21 | If a `KeyValuePair()` is inserted at a location that is already occupied your 22 | method should throw an `Error` with an appropriate error message. 23 | 24 | Read the specs in `test/hash-table-pt2-spec.js` for more details. 25 | -------------------------------------------------------------------------------- /week-4/d3-context-bind-call-apply/practices/01-context-regular-functions/context.js: -------------------------------------------------------------------------------- 1 | function eat() { 2 | console.log(`${this.name} eats fish food`); 3 | } 4 | 5 | class Fish { 6 | constructor(name) { 7 | this.name = name; 8 | } 9 | 10 | swim() { 11 | console.log(`${this.name} swimming in the water`); 12 | } 13 | } 14 | 15 | const nemo = new Fish('Nemo'); 16 | 17 | /********************************* Scenario 1 *********************************/ 18 | // eat(); // ? 19 | 20 | 21 | /********************************* Scenario 2 *********************************/ 22 | // nemo.eat = eat; 23 | // nemo.eat(); // ? 24 | 25 | 26 | /********************************* Scenario 3 *********************************/ 27 | // nemo.eat = eat; 28 | // eat(); // ? 29 | 30 | 31 | /********************************* Scenario 4 *********************************/ 32 | // nemo.swim(); // ? 33 | 34 | 35 | /********************************* Scenario 5 *********************************/ 36 | // const swim = nemo.swim; 37 | // swim(); // ? 38 | -------------------------------------------------------------------------------- /week-4/d2-es6-classes/practices/04-polymorphism/README.md: -------------------------------------------------------------------------------- 1 | # Practice: Polymorphism 2 | 3 | **Polymorphism** is a principle that allows one method to have different 4 | implementations for inherited classes. In this practice, you will be writing 5 | code that demonstrates this principle. 6 | 7 | ## Set up 8 | 9 | Clone the starter from the **Download** link at the bottom of this page. 10 | 11 | ## Directions 12 | 13 | Implement the following in the __classes__ folder. 14 | 15 | Overwrite `Person`'s `introduce` instance method in `Student` and `Teacher` 16 | classes. 17 | 18 | 1. `Student`'s `introduce` should return: "Hello. I am `` 19 | ``, and I study ``." 20 | 2. `Teacher`'s `introduce` should return: "Hello. I am `` 21 | ``, and I have been teaching `` for `` 22 | years." 23 | 24 | Run the test specs in the __test/introduce-spec.js__ file to test that you 25 | have implemented the methods correctly: 26 | 27 | ```shell 28 | npm test test/introduce-spec.js 29 | ``` 30 | -------------------------------------------------------------------------------- /week-6/d3-binary-search-trees/practices/01-binary-search-trees/binary-search-tree.js: -------------------------------------------------------------------------------- 1 | // Do not change this 2 | class TreeNode { 3 | constructor(val) { 4 | this.val = val; 5 | this.left = null; 6 | this.right = null; 7 | } 8 | } 9 | 10 | class BinarySearchTree { 11 | 12 | constructor() { 13 | // Your code here 14 | } 15 | 16 | insert(val, currentNode=this.root) { 17 | // Your code here 18 | } 19 | 20 | search(val) { 21 | // Your code here 22 | } 23 | 24 | 25 | preOrderTraversal(currentNode = this.root) { 26 | // Your code here 27 | } 28 | 29 | 30 | inOrderTraversal(currentNode = this.root) { 31 | // Your code here 32 | } 33 | 34 | 35 | postOrderTraversal(currentNode = this.root) { 36 | // Your code here 37 | } 38 | 39 | // Breadth First Traversal - Iterative 40 | breadthFirstTraversal() { 41 | // your code here 42 | } 43 | 44 | // Depth First Traversal - Iterative 45 | depthFirstTraversal() { 46 | // your code here 47 | } 48 | } 49 | 50 | module.exports = { BinarySearchTree, TreeNode }; 51 | -------------------------------------------------------------------------------- /week-5/d1-big-o-arrays/practices/01-timing-benchmarks/README-phase-1.md: -------------------------------------------------------------------------------- 1 | # Practice Timing Benchmarks Phase 1 - Implementation 2 | 3 | The first step is to implement the code you will be testing. 4 | 5 | Read through the starter and specs, **phase-1.js** and **test/phase-1-spec.js**, 6 | for details. 7 | 8 | Run tests with `npm test test/phase-1-spec.js` 9 | 10 | ## addNums 11 | 12 | `addNums(n)` takes in a positive integer and returns the sum of all numbers 13 | 1 through n. 14 | 15 | For example `addNums(5)` will add `1 + 2 + 3 + 4 + 5` and return `15`. 16 | 17 | ```js 18 | // 1 + 2 + 3 + 4 + 5 = 15 19 | addNums(5); // 15 20 | ``` 21 | 22 | Solve this with a for-loop. 23 | 24 | ## addManyNums 25 | 26 | `addManyNums(n)` takes in a positive integer and returns the sum of `addNums(1)` 27 | through `addNums(n)`. 28 | 29 | For example `addManyNums(3)` is the same as `addNums(1) + addNums(2) + 30 | addNums(3)`, or `1 + 3 + 6` which equals `10`. 31 | 32 | ```js 33 | // addNums(1) + addNums(2) + addNums(3) 34 | // = 1 + 3 + 6 35 | // = 10 36 | addManyNums(3); // 10 37 | ``` 38 | -------------------------------------------------------------------------------- /week-4/d4-test-driven-development/practices/02-unit-testing/README.md: -------------------------------------------------------------------------------- 1 | # Practice: Unit Testing with Mocha and Chai 2 | 3 | In this practice, you will create unit tests with the `mocha` testing library 4 | and the `chai` assertion library. 5 | 6 | ## Set up 7 | 8 | Clone the starter from the **Download** link at the bottom of this page. 9 | 10 | Run `npm install` to download dependencies. 11 | 12 | ## Instructions 13 | 14 | 1. In the file **funcs.js**, you will find three skeleton functions. Your job is 15 | to complete those functions according to the specs found in 16 | **test/funcs-spec.js**. 17 | 2. In the file **class.js**, you will find a class `Word`. Your job is to write 18 | the test code in **test/class-spec.js** to test the constructor, its 19 | variables, and the instance methods found in the `Word` class. 20 | 21 | Run `npm test` to confirm your code is written correctly. 22 | 23 | ### Helpful links 24 | 25 | [Mocha Documentation](https://mochajs.org/) 26 | [Chai Documentation](https://www.chaijs.com/) 27 | [MDN Documentation](https://developer.mozilla.org/en-US/) 28 | -------------------------------------------------------------------------------- /week-4/d4-test-driven-development/practices/01-error-handling/README.md: -------------------------------------------------------------------------------- 1 | # Practice: Error Handling 2 | 3 | In this practice, you will practice reading, throwing and handling JavaScript 4 | runtime errors. 5 | 6 | ## Set up 7 | 8 | Clone the starter from the **Download** link at the bottom of this page. 9 | 10 | ## Instructions 11 | 12 | Implement the following in the __error-handling.js__ file. 13 | 14 | 1. `sum` function is throwing an error! Determine why the error is thrown, and 15 | handle only that particular error type using `try...catch`. Print the error 16 | message if the code is throwing the error type you expect 17 | 2. Create `sayName(name)` function that will print the name that is passed to it 18 | if `name` argument is a string. It should throw a `TypeError` with a message 19 | of "Invalid name! Must be a string!" if `name` is not a string. Run the 20 | `sayName` function test cases inside of `try...catch` and print out the error 21 | message if an error is thrown. 22 | 3. Come up with a test case that will cause the `greeting` function to throw 23 | the `Error`. When an error is thrown from that test case, catch it and print 24 | out "Hello World!" 25 | -------------------------------------------------------------------------------- /week-4/d2-es6-classes/notes/book.js: -------------------------------------------------------------------------------- 1 | class Book { 2 | constructor(title, series, author) { 3 | this.title = title; 4 | this.series = series; 5 | this.author = author; 6 | } 7 | 8 | // Example of an instance method 9 | getInformation() { 10 | return `${this.title} by ${this.author}`; 11 | } 12 | 13 | // Static method that accepts a variable number 14 | // of Book instances and returns an array of their titles. 15 | // Notice the use of a rest parameter (...books) 16 | // to capture the passed parameters as an array of values. 17 | static getTitles(...books) { 18 | return books.map((book) => book.title); 19 | } 20 | } 21 | 22 | const fellowshipOfTheRing = new Book( 23 | "The Fellowship of the Ring", 24 | "The Lord of the Rings", 25 | "J.R.R. Tolkien" 26 | ); 27 | 28 | // console.log(fellowshipOfTheRing.getTitles()); 29 | console.log(fellowshipOfTheRing instanceof Book) 30 | if (fellowshipOfTheRing instanceof Book) { 31 | //do some stuff 32 | } 33 | 34 | const newBook = new Book('Song of Ice and Fire', 'Game of Thrones', 'Old Man Winter'); 35 | // console.log(newBook.getInformation()); 36 | 37 | console.log(Book.getTitles([fellowshipOfTheRing, newBook])) -------------------------------------------------------------------------------- /week-4/d4-test-driven-development/practices/02-unit-testing/test/class-spec.js: -------------------------------------------------------------------------------- 1 | const chai = require("chai"); 2 | const expect = chai.expect; 3 | 4 | const { Word } = require("../class"); 5 | 6 | describe("Word", function () { 7 | describe("Word constructor function", function () { 8 | it('should have a "word" property', function () { 9 | expect.fail("replace with your code"); 10 | }); 11 | 12 | it('should set the "word" property when a new word is created', function () { 13 | expect.fail("replace with your code"); 14 | }); 15 | }); 16 | 17 | describe("removeVowels function", function () { 18 | it("should return a the word with all vowels removed", function () { 19 | expect.fail("replace with your code"); 20 | }); 21 | }); 22 | 23 | describe("removeConsonants function", function () { 24 | it("should return the word with the consonants removed", function () { 25 | expect.fail("replace with your code"); 26 | }); 27 | }); 28 | 29 | describe("pigLatin function", function () { 30 | it("should return the word converted to pig latin", function () { 31 | expect.fail("replace with your code"); 32 | }); 33 | }); 34 | }); 35 | -------------------------------------------------------------------------------- /week-5/d1-big-o-arrays/practices/01-timing-benchmarks/README-phase-3.md: -------------------------------------------------------------------------------- 1 | # Practice Timing Benchmarks Phase 3 - Timing your code 2 | 3 | Copy your `addNums10` and `addManyNums10` into the phase 3 starter. Your task 4 | is to add timing reports to your code at key points to measure the time it 5 | takes to run with various input sizes. 6 | 7 | Read through the starter, **phase-3.js**, for details. 8 | 9 | There are no test specs for this exercise but you can run the timing tests by 10 | running the command `node phase-3.js` 11 | 12 | ## Directions 13 | 14 | 1. Copy your `addNums10` and `addManyNums10` code into `addNums10Timing` and 15 | `addManyNums10Timing`. 16 | 2. Use `console.time()`, `console.timeLog()` and `console.timeEnd()` to print 17 | timestamps after each call of `addNums` and `addManyNums` 18 | 3. Use `Date.now()` to print the amount of milliseconds each call takes to 19 | execute. 20 | 4. Plot the results of `addNums10(1000000)` in a Google Sheet 21 | 5. Plot the results of `addManyNums10(5000)` in a Google Sheet 22 | 6. Identify the time complexity of both functions 23 | 7. **BONUS**: Implement `addNums100` and `addManyNums100` and chart the 24 | performance for better resolution. 25 | -------------------------------------------------------------------------------- /week-6/d4-graphs/notes/graphs.js: -------------------------------------------------------------------------------- 1 | /* 2 | Graph Vocabulary: 3 | Vertex: A node in the graph. Vertex and node can be used interchangeably 4 | Directed edge: A one-way connection from one vertex to another 5 | Undirected edge: A two-way connection between two vertices. Functionally the same as a bidirectional edge 6 | Bidirectional edge: A two-way connection between two vertices that can be traversed in either direction 7 | Edge weight: The cost of traversing an edge. 8 | Cyclic/acyclic: A cyclic graph is a graph with at least 1 cycle, or the potential to have a cycle 9 | Adjacency list: A way of representing a graph in code with an object 10 | 11 | 12 | */ 13 | 14 | //Many times we represent graphs using adjacency lists: 15 | 16 | const graph1 = { 17 | T: ["V"], 18 | U: ["V"], 19 | V: [], 20 | }; 21 | 22 | const graph2 = { 23 | X: ["Y"], 24 | Y: ["Z"], 25 | Z: ["X"], 26 | }; 27 | 28 | const graph3 = { 29 | A: ["B", "C", "E"], 30 | B: [], 31 | C: ["B", "D"], 32 | D: [], 33 | E: ["A"], 34 | F: ["E"], 35 | }; 36 | 37 | //an undirected graph may look like this: 38 | const undirected = { 39 | 1: [2, 5], 40 | 2: [1, 3, 5], 41 | 3: [2, 4], 42 | 4: [3, 5, 6], 43 | 5: [1, 2, 4], 44 | 6: [4], 45 | }; -------------------------------------------------------------------------------- /week-6/d1-sorting-bubble-insertion-selection/practices/03-selection-sort/selection-sort.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | function selectionSort(arr) { 4 | 5 | // Copy the original array 6 | 7 | // Create an array to store the sorted values 8 | 9 | // While the array is not empty... 10 | 11 | // Do not move this console.log 12 | console.log(sorted.join(",")); 13 | 14 | // Find the index of the minimum value in the unsorted half 15 | 16 | // Save and remove the value at the min index 17 | 18 | // Add the min value to the end of the sorted array 19 | 20 | } 21 | 22 | 23 | 24 | function selectionSortInPlace(arr) { 25 | 26 | // Set a pointer at zero diving the array into sorted and unsorted halves 27 | 28 | // Repeat while the unsorted half is not empty: 29 | 30 | // Do not move this console.log 31 | console.log(arr.join(",")); 32 | 33 | // Find the index of the minimum value in the unsorted half 34 | 35 | // Save the min value 36 | 37 | // Shift every unsorted value to the left of the min value to the right by 1 38 | 39 | // Put the min value at the divider 40 | 41 | // Increment the divider and repeat 42 | 43 | } 44 | 45 | 46 | module.exports = [selectionSort, selectionSortInPlace]; 47 | -------------------------------------------------------------------------------- /week-6/d3-binary-search-trees/practices/01-binary-search-trees/README-pt3.md: -------------------------------------------------------------------------------- 1 | # Practice: Binary Search Tree - Part 3 2 | 3 | In this exercise, you will be recursively traversing a basic binary search tree. 4 | 5 | ## Setup 6 | 7 | 1. Continue working from the same starter as part 1 and 2 8 | 2. Read the instructions and test specs to understand the problem 9 | 3. Fill out the code until tests are all green 10 | 11 | ## Part 3: Binary Search Tree recursive traversal 12 | 13 | Implement functions that will print out the tree nodes with a pre-order, 14 | in-order and post-order traversal. 15 | 16 | ```plaintext 17 | 4 18 | / \ 19 | 3 5 20 | ``` 21 | 22 | `preOrderTraversal()` prints the node value first, then recursively visits the 23 | left and right nodes. The example tree would print out `4, 3, 5`. 24 | 25 | `inOrderTraversal()` recursively visits the left node, then prints the current 26 | node value, then recursively visits the right node. The example tree would 27 | print out `3, 4, 5`. 28 | 29 | `postOrderTraversal()` recursively visits the left and right nodes, then 30 | prints the current node value. The example tree would print out `3, 5, 4`. 31 | 32 | Read through the specs in `test/binary-search-tree-spec.js` for more details. -------------------------------------------------------------------------------- /week-5/d4-hash-tables-and-sets/practices/01-hash-tables/test/hash-table-pt3-spec.js: -------------------------------------------------------------------------------- 1 | const { expect } = require('chai'); 2 | 3 | const HashTable = require('../hash-table.js'); 4 | 5 | 6 | describe('Hash table insert with hash collisions', () => { 7 | 8 | let hashTable; 9 | 10 | beforeEach(function () { 11 | 12 | hashTable = new HashTable(2); 13 | 14 | }); 15 | 16 | it('insert handles hash collisions with linked lists', () => { 17 | 18 | hashTable.insertWithHashCollisions("key-1", "val-1"); 19 | hashTable.insertWithHashCollisions("key-2", "val-2"); 20 | hashTable.insertWithHashCollisions("key-3", "val-3"); 21 | 22 | expect(hashTable.count).to.equal(3); 23 | expect(hashTable.capacity).to.equal(2); 24 | expect(hashTable.data.length).to.equal(2); 25 | 26 | const pairC = hashTable.data[0]; 27 | const pairB = hashTable.data[1]; 28 | const pairA = hashTable.data[0].next; 29 | 30 | expect(pairA.key).to.equal("key-1"); 31 | expect(pairA.value).to.equal("val-1"); 32 | 33 | expect(pairB.key).to.equal("key-2"); 34 | expect(pairB.value).to.equal("val-2"); 35 | 36 | expect(pairC.key).to.equal("key-3"); 37 | expect(pairC.value).to.equal("val-3"); 38 | 39 | }); 40 | 41 | }); 42 | -------------------------------------------------------------------------------- /week-4/d5-es5-class-syntax/practices/02-es5-classes/test/dog-spec.js: -------------------------------------------------------------------------------- 1 | const chai = require("chai"); 2 | const expect = chai.expect; 3 | const spies = require('chai-spies'); 4 | chai.use(spies); 5 | 6 | const Dog = require('../classes/dog'); 7 | 8 | describe("Dog", () => { 9 | let consoleSpy; 10 | let sammy; 11 | 12 | beforeEach(() => { 13 | consoleSpy = chai.spy.on(console, 'log'); 14 | sammy = new Dog('Sammy', 15); 15 | }); 16 | 17 | afterEach(() => { 18 | chai.spy.restore(console); 19 | }); 20 | 21 | describe("constructor(name, age)", () => { 22 | it("should initialize the name property to be set to the given name", () => { 23 | expect(sammy.name).to.eq('Sammy'); 24 | }); 25 | 26 | it("should initialize the age property to be set to the given age", () => { 27 | expect(sammy.age).to.eq(15); 28 | }); 29 | }); 30 | 31 | describe("bark()", () => { 32 | it("should print 'Bark' to the console", () => { 33 | sammy.bark(); 34 | expect(consoleSpy).to.have.been.called.with("Bark"); 35 | }); 36 | }); 37 | 38 | describe("static diet()", () => { 39 | it("should return 'carnivore'", () => { 40 | expect(Dog.diet()).to.eq('carnivore'); 41 | }); 42 | }); 43 | }); 44 | -------------------------------------------------------------------------------- /week-5/d4-hash-tables-and-sets/practices/01-hash-tables/test/hash-table-pt4-spec.js: -------------------------------------------------------------------------------- 1 | const { expect } = require('chai'); 2 | 3 | const HashTable = require('../hash-table.js'); 4 | 5 | 6 | describe('Hash table complete insert method', () => { 7 | 8 | let hashTable; 9 | 10 | beforeEach(function () { 11 | 12 | hashTable = new HashTable(2); 13 | 14 | }); 15 | 16 | it('insert handles hash collisions AND updates values for same key inserts', () => { 17 | 18 | hashTable.insert("key-1", "val-1"); 19 | hashTable.insert("key-2", "val-2"); 20 | hashTable.insert("key-3", "val-3"); 21 | hashTable.insert("key-1", "val-100000"); 22 | 23 | expect(hashTable.count).to.equal(3); 24 | expect(hashTable.capacity).to.equal(2); 25 | expect(hashTable.data.length).to.equal(2); 26 | 27 | const pairC = hashTable.data[0]; 28 | const pairB = hashTable.data[1]; 29 | const pairA = hashTable.data[0].next; 30 | 31 | expect(pairA.key).to.equal("key-1"); 32 | expect(pairA.value).to.equal("val-100000"); 33 | 34 | expect(pairB.key).to.equal("key-2"); 35 | expect(pairB.value).to.equal("val-2"); 36 | 37 | expect(pairC.key).to.equal("key-3"); 38 | expect(pairC.value).to.equal("val-3"); 39 | 40 | }); 41 | 42 | }); 43 | -------------------------------------------------------------------------------- /week-4/d2-es6-classes/practices/03-inheritance/classes/person.js: -------------------------------------------------------------------------------- 1 | class Person { 2 | constructor(firstName, lastName, age) { 3 | this.firstName = firstName; 4 | this.lastName = lastName; 5 | this.age = age; 6 | } 7 | 8 | introduce() { 9 | return `Hi, I'm ${this.firstName} ${this.lastName}, and I'm ${this.age} years old.`; 10 | } 11 | 12 | static introducePeople(people) { 13 | if (!Array.isArray(people)) { 14 | // throw new Error("introducePeople only takes an array as an argument."); 15 | console.log("introducePeople only takes an array as an argument."); 16 | return; 17 | } 18 | 19 | for (let person of people) { 20 | if (!(person instanceof Person)) { 21 | // throw new Error("All items in array must be Person class instances."); 22 | console.log("All items in array must be Person class instances."); 23 | return; 24 | } 25 | } 26 | 27 | people.forEach((person) => person.introduce()); 28 | } 29 | } 30 | 31 | /****************************************************************************/ 32 | /******************* DO NOT EDIT CODE BELOW THIS LINE ***********************/ 33 | 34 | try { 35 | module.exports = Person; 36 | } catch { 37 | module.exports = null; 38 | } 39 | -------------------------------------------------------------------------------- /week-4/d2-es6-classes/practices/04-polymorphism/classes/person.js: -------------------------------------------------------------------------------- 1 | class Person { 2 | constructor(firstName, lastName, age) { 3 | this.firstName = firstName; 4 | this.lastName = lastName; 5 | this.age = age; 6 | } 7 | 8 | introduce() { 9 | return `Hi, I'm ${this.firstName} ${this.lastName}, and I'm ${this.age} years old.`; 10 | } 11 | 12 | static introducePeople(people) { 13 | if (!Array.isArray(people)) { 14 | // throw new Error("introducePeople only takes an array as an argument."); 15 | console.log("introducePeople only takes an array as an argument."); 16 | return; 17 | } 18 | 19 | for (let person of people) { 20 | if (!(person instanceof Person)) { 21 | // throw new Error("All items in array must be Person class instances."); 22 | console.log("All items in array must be Person class instances."); 23 | return; 24 | } 25 | } 26 | 27 | people.forEach((person) => person.introduce()); 28 | } 29 | } 30 | 31 | /****************************************************************************/ 32 | /******************* DO NOT EDIT CODE BELOW THIS LINE ***********************/ 33 | 34 | try { 35 | module.exports = Person; 36 | } catch { 37 | module.exports = null; 38 | } 39 | -------------------------------------------------------------------------------- /week-4/d4-test-driven-development/practices/02-unit-testing/class.js: -------------------------------------------------------------------------------- 1 | class Word { 2 | constructor(word) { 3 | this.word = word; 4 | } 5 | 6 | removeVowels() { 7 | let vowels = "aeiouAEIOU"; 8 | let newWord = ""; 9 | for (let i = 0; i < this.word.length; i++) { 10 | let char = this.word[i]; 11 | if (!vowels.includes(char)) { 12 | newWord += char; 13 | } 14 | } 15 | return newWord; 16 | } 17 | 18 | removeConsonants() { 19 | let vowels = "aeiouAEIOU"; 20 | let newWord = ""; 21 | for (let i = 0; i < this.word.length; i++) { 22 | let char = this.word[i]; 23 | if (vowels.includes(char)) { 24 | newWord += char; 25 | } 26 | } 27 | return newWord; 28 | } 29 | 30 | pigLatin() { 31 | let vowels = "aeiouAEIOU"; 32 | 33 | if (vowels.includes(this.word[0])) { 34 | return this.word + "yay"; 35 | } 36 | 37 | for (let i = 0; i < this.word.length; i++) { 38 | let char = this.word[i]; 39 | if (vowels.includes(char)) { 40 | let first_half = this.word.slice(0, i); 41 | let second_half = this.word.slice(i); 42 | return second_half + first_half + "ay"; 43 | } 44 | } 45 | } 46 | } 47 | 48 | module.exports = { Word }; 49 | -------------------------------------------------------------------------------- /week-4/d3-context-bind-call-apply/practices/03-call-apply/README.md: -------------------------------------------------------------------------------- 1 | # Call and Apply Practice 2 | 3 | In this exercise, you will be debugging code that has lost context. 4 | 5 | ## Set up 6 | 7 | Clone the starter from the **Download** link at the bottom of this page. 8 | 9 | ## Phase 1: Greet 10 | 11 | Take a look at the code in the __greet.js__ file. 12 | 13 | If you run the file with `node greet.js`, you will see the following printed 14 | to the terminal: 15 | 16 | ```plaintext 17 | undefined [object Object]! 18 | undefined [object Object]! 19 | ``` 20 | 21 | Without modifying the `say` function, make the file print out the following: 22 | 23 | ```plaintext 24 | Hello, John! 25 | Hey there, Michael! 26 | ``` 27 | 28 | ## Phase 2: Grades 29 | 30 | Take a look at the code in the __grade.js__ file. 31 | 32 | The code instantiates a new `Gradebook` imported from the 33 | __classes/gradebook.js__ file. 34 | 35 | If you run the __grade.js__ file with `node greet.js`, you will get an error. 36 | 37 | Without modifying `GradeBook`, `grades`, or `gradesAvg`, can you correctly 38 | print out the average of the grades with and without a 20 point bonus? A correct 39 | function will return the following from `node grade.js` 40 | 41 | ```plaintext 42 | Grade list 43 | 58 44 | 78 45 | ``` -------------------------------------------------------------------------------- /week-6/d3-binary-search-trees/practices/01-binary-search-trees/README-pt1.md: -------------------------------------------------------------------------------- 1 | # Practice: Binary Search Tree - Part 1 2 | 3 | In this exercise, you will be implementing a basic binary search tree. 4 | 5 | ## Setup 6 | 7 | 1. Download the starter at the bottom of this page 8 | 2. Install all packages using `npm install` 9 | 3. Read the instructions and test specs to understand the problem 10 | 4. Fill out the code until tests are all green 11 | 12 | ## Part 1: Binary Search Tree construction 13 | 14 | Start by implementing the class constructor and `insert` method in 15 | `binary-search-tree.js`. 16 | 17 | `insert(val)` should insert new tree node with the given value into the 18 | correct location in the binary search tree. 19 | 20 | For example, inserting `4` into the empty tree will set the root node to 4. 21 | Inserting `3`, then `5` will insert two nodes to the left and right of the 22 | root respectively. The resulting tree will look like this: 23 | 24 | ```plaintext 25 | 4 26 | / \ 27 | 3 5 28 | ``` 29 | 30 | **hint** you may add default parameters to your functions to aid in recursion. 31 | For example, `insert(currentNode=this.root)` will default to inserting at the 32 | root, but allow you to pass in a child node to insert as well. 33 | 34 | Read through the specs in `test/binary-search-tree-spec.js` for more details. -------------------------------------------------------------------------------- /week-4/d1-basic-coding-principles/practices/03-dry/practice.js: -------------------------------------------------------------------------------- 1 | function multiplyBiggerNumByTwo(num1, num2) { 2 | let bigNum; 3 | if (num1 > num2) { 4 | bigNum = num1; 5 | return bigNum * 2; 6 | } else { 7 | bigNum = num2; 8 | return bigNum * 2; 9 | } 10 | } 11 | 12 | function divideBiggerNumByThree(num1, num2) { 13 | let bigNum; 14 | if (num1 > num2) { 15 | bigNum = num1; 16 | return bigNum / 3; 17 | } else { 18 | bigNum = num2; 19 | return bigNum / 3; 20 | } 21 | } 22 | 23 | function eatMostTacos(sum1, sum2) { 24 | let bigNum; 25 | if (sum1 > sum2) { 26 | bigNum = sum1; 27 | return `I ate ${bigNum} tacos.`; 28 | } else { 29 | bigNum = sum2; 30 | return `I ate ${bigNum} tacos.`; 31 | } 32 | } 33 | 34 | function adoptSmallerDog(weight1, weight2) { 35 | let smallDog; 36 | if (weight1 < weight2) { 37 | smallDog = weight1; 38 | return `I adopted a dog that weighs ${smallDog} pounds.`; 39 | } else { 40 | smallDog = weight2; 41 | return `I adopted a dog that weighs ${smallDog} pounds.`; 42 | } 43 | } 44 | 45 | 46 | /**************************************************************************/ 47 | /* DO NOT CHANGE THE CODE BELOW */ 48 | module.exports = { 49 | multiplyBiggerNumByTwo, 50 | divideBiggerNumByThree, 51 | eatMostTacos, 52 | adoptSmallerDog 53 | }; 54 | -------------------------------------------------------------------------------- /week-5/d4-hash-tables-and-sets/practices/01-hash-tables/README-pt3.md: -------------------------------------------------------------------------------- 1 | # Hash Table Practice Part 3 2 | 3 | In this four-part exercise, you will start implementing a hash table that 4 | handles hash collisions with linked list chaining. 5 | 6 | ## Setup 7 | 8 | 1. Continue working in the same starter as part 1 and 2 9 | 2. Run specs with `npm test test/hash-table-pt3-spec.js` 10 | 11 | ## Hash table insert with hash collisions 12 | 13 | You will now write an insert function to handle hash collisions with linked 14 | list chaining. 15 | 16 | `insertWithHashCollisions(key, value)` will create a new `KeyValuePair()` 17 | with the input key and value and store it in the data bucket location returned 18 | by `hashMod(key)`. 19 | 20 | If that bucket is already occupied, it will insert the new `KeyValuePair` to 21 | the head of the linked list in the bucket. 22 | 23 | > Hint: if you are to add to the *head* of the linked list in a hash 24 | > table, how might that be similar to how you have done that before? 25 | 26 | Note that the test specs inserts 3 key/value pairs into a hash table with a 27 | capacity of 2. Linked list chaining allows the linked list to fill past 28 | capacity at the cost of performance. 29 | 30 | The bucket order of keys is reliant on a valid hash function from part 1. 31 | 32 | Read the specs in `test/hash-table-pt3-spec.js` for more details. 33 | -------------------------------------------------------------------------------- /week-6/d3-binary-search-trees/notes/binary-search-trees.md: -------------------------------------------------------------------------------- 1 | # Tree Terminology 2 | 3 | - Node: A tree component that contains one value and pointers to other nodes 4 | - Edge: Another name for a pointer 5 | - Root node: The top node in a tree 6 | - Edge: Another name for a pointer 7 | - Parent/child node: A parent node points to child nodes 8 | - Neighbor: Either a parent or child node 9 | - Subtree: A tree whose root is the child of another node in the tree 10 | - Branch node: A node with at least one child node 11 | - Leaf node: A node with no children 12 | - Level: The number of edges between a given node and the root node 13 | - Width: The number of nodes in a given level 14 | - Height: The number of edges between the root node and the bottom-most node 15 | 16 | # Properties of Binary Search Trees 17 | - The tree starts at the root 18 | - nodes whose values are less than the current node go to the left 19 | - nodes whose values are more than the current node go to the left 20 | - O (log n) search, insertion and deletion complexity 21 | - Each node has three properties: value, left and right 22 | 23 | ## Balanced vs Unbalanced: 24 | 25 | A balanced tree means that the left and right subtrees of every node differ in height by NO MORE THAN 1. 26 | An unbalanced tree is more expensive to traverse, so searching in an unbalanced tree would have an O (n) complexity. 27 | 28 | -------------------------------------------------------------------------------- /week-4/d1-basic-coding-principles/notes/srp-dry.md: -------------------------------------------------------------------------------- 1 | # Single Responsibility Principle (SRP) & DRY (Don't Repeat Yourself) 2 | 3 | SRP refers to the idea that a function or class or method should be responsible 4 | for just as much functionality as is necessary...no more, no less. 5 | 6 | ## Single Responsibility Principle: Do one thing and do it well 7 | 8 | An example is given in your reading using a JavaScript class (that you will 9 | learn about tomorrow). The class Book should only contain the properties and 10 | methods that pertain to descriptions and behaviors of a book. 11 | 12 | The second class SimplePrinter that was created later holds the 13 | descriptors(properties) and the behaviors related to printing some type of 14 | object. 15 | 16 | Following the guidelines of SRP sets up easier to read code that just makes more 17 | sense. 18 | 19 | ## DRY - Don't Repeat Yourself: 20 | 21 | Making code that is more readable and more reusable should be every programmer's 22 | goal. By taking a critical look at your code and identifying places where you 23 | may have identical logic repeated throughout and creating smaller, more reusable 24 | functions or methods to contain that logic, allows you to write code that other 25 | programmers will be able to follow more closely and accurately, leading to 26 | maintainable code. 27 | 28 | The opposite of DRY coding is, of course, WET. We Enjoy Typing. -------------------------------------------------------------------------------- /week-6/d1-sorting-bubble-insertion-selection/practices/01-bubble-sort/test/sort-specs.js: -------------------------------------------------------------------------------- 1 | const { expect } = require('chai'); 2 | 3 | const chai = require('chai'); 4 | const spies = require('chai-spies'); 5 | 6 | chai.use(spies); 7 | 8 | const bubbleSort = require("../bubble-sort.js"); 9 | 10 | describe ('Basic Sorting Algorithms', function () { 11 | 12 | let arr; 13 | let consoleSpy; 14 | 15 | beforeEach(function () { 16 | 17 | consoleSpy = chai.spy.on(console, 'log'); 18 | 19 | arr = [2,4,6,8,1,3,5,7,9]; 20 | }); 21 | 22 | afterEach(() => { 23 | chai.spy.restore(console, 'log'); 24 | }); 25 | 26 | it('performs a bubble sort', function () { 27 | 28 | bubbleSort(arr); 29 | 30 | expect(consoleSpy).on.nth(1).be.called.with('2,4,6,1,8,3,5,7,9'); 31 | expect(consoleSpy).on.nth(2).be.called.with('2,4,6,1,3,8,5,7,9'); 32 | expect(consoleSpy).on.nth(3).be.called.with('2,4,6,1,3,5,8,7,9'); 33 | expect(consoleSpy).on.nth(4).be.called.with('2,4,6,1,3,5,7,8,9'); 34 | expect(consoleSpy).on.nth(5).be.called.with('2,4,1,6,3,5,7,8,9'); 35 | expect(consoleSpy).on.nth(6).be.called.with('2,4,1,3,6,5,7,8,9'); 36 | expect(consoleSpy).on.nth(7).be.called.with('2,4,1,3,5,6,7,8,9'); 37 | expect(consoleSpy).on.nth(8).be.called.with('2,1,4,3,5,6,7,8,9'); 38 | expect(consoleSpy).on.nth(9).be.called.with('2,1,3,4,5,6,7,8,9'); 39 | expect(consoleSpy).on.nth(10).be.called.with('1,2,3,4,5,6,7,8,9'); 40 | 41 | }); 42 | 43 | }); 44 | 45 | -------------------------------------------------------------------------------- /week-4/d2-es6-classes/practices/02-basic-class-syntax/README.md: -------------------------------------------------------------------------------- 1 | # Practice: Basic Class Syntax 2 | 3 | In this exercise, you will be creating a class by creating a constructor and 4 | defining static and instance methods. 5 | 6 | ## Set up 7 | 8 | Clone the starter from the **Download** link at the bottom of this page. 9 | 10 | ## Directions 11 | 12 | Implement the following in the __classes/person.js__ file. 13 | 14 | Create a class `Person` that has the following: 15 | 16 | 1. instance variables that include `firstName`, `lastName`, and `age` 17 | 2. an instance method called `introduce` that will introduce the person by using 18 | `console.log` with a string saying, "Hi, I'm `` ``, and 19 | I'm `` years old.". 20 | 3. a static method called `introducePeople` that will take in an array of 21 | `Person` instances. Have the method `console.log` an error message of 22 | "introducePeople only takes an array as an argument." if the argument is not 23 | of type `Array`. Have the method `console.log` an error message of 24 | "All items in array must be Person class instances." if any of the items in 25 | the array are not instances of the `Person` class. If there are no errors 26 | logged to the console, call `introduce` on each of the `People` instances in 27 | the input array. 28 | 29 | Run the test specs in the __test/person-spec.js__ file to test that you 30 | have created the `Person` class correctly: 31 | 32 | ```shell 33 | npm test 34 | ``` -------------------------------------------------------------------------------- /week-4/d4-test-driven-development/notes/error-syntax-notes.md: -------------------------------------------------------------------------------- 1 | Identify the definitions of SyntaxError, ReferenceError, and TypeError 2 | - SyntaxError 3 | - an error in how the code is written 4 | - encountered at compile-time, ie the code cannot be parsed to determine the instructions 5 | - since our code cannot be run, SyntaxErrors cannot be caught by a try-catch block 6 | - common examples would be: 7 | - a misspelled function keyword (`function broken() {...}`) 8 | - incorrect number of curly braces 9 | - ReferenceError 10 | - when a nonexistent variable is referenced 11 | - most commonly seen when you mistype a variable name, or refer to one out of the current scope 12 | ```javascript 13 | const puppy = "puppy"; 14 | console.log(pupppy); // mistyped variable name 15 | ``` 16 | 17 | ```javascript 18 | function callPuppy() { 19 | const puppy = "puppy"; 20 | } 21 | console.log(puppy); // puppy is not in scope, it was created in the callPuppy function 22 | ``` 23 | - TypeError 24 | - when a variable or parameter is not of a valid type 25 | - can also be seen if we are trying to modify a value that cannot be changed (because a variable is declared with `const` instead of `let`, for example) 26 | ```javascript 27 | let dog; // Remember unassigned variables are undefined! 28 | dog(); // TypeError: dog is not a function 29 | 30 | const puppy = "puppy"; 31 | puppy = "apple"; // TypeError: Assignment to constant variable. 32 | ``` 33 | 34 | 35 | -------------------------------------------------------------------------------- /week-5/d1-big-o-arrays/practices/01-timing-benchmarks/README-phase-2.md: -------------------------------------------------------------------------------- 1 | # Practice Timing Benchmarks Phase 2 - Scale testing harness 2 | 3 | Next, you will be creating functions to test your code with a variety of 4 | input sizes. 5 | 6 | Read through the starter and specs, **phase-2.js** and **test/phase-2-spec.js**, 7 | for details. 8 | 9 | Run tests with `npm test test/phase-2-spec.js` 10 | 11 | ## addNums10 12 | 13 | `addNums10(increment)` takes in an increment value and runs `addNums` 10 14 | times, increasing by the increment each time. It should return an array 15 | containing the 10 return values. 16 | 17 | For example, `addNums10(1)` will return an array containing addNums for values 18 | 1 through 10. 19 | 20 | ```js 21 | // increment = 1 22 | // addNums10(increment) 23 | [ 24 | addNums(1), // 1 25 | addNums(2), // 3 26 | addNums(3), // 6 27 | addNums(4), // 10 28 | addNums(5), // 15 29 | addNums(6), // 21 30 | addNums(7), // 28 31 | addNums(8), // 36 32 | addNums(9), // 45 33 | addNums(10) // 55 34 | ] 35 | // prints out [ 1, 3, 6, 10, 15, 21, 28, 36, 45, 55 ] 36 | ``` 37 | 38 | Passing in an increment of 10 will return values for `[addNums(10), 39 | addNums(20), ...]`. 40 | 41 | ## addManyNums10 42 | 43 | `addManyNums10(increment)` takes in an increment value and runs `addManyNums` 44 | 10 times, increasing by the increment each time. It should return an array 45 | containing the 10 return values. 46 | 47 | Passing in an increment of 10 will return values for `[addManyNums10(10), 48 | addManyNums10(20), ...]`. 49 | -------------------------------------------------------------------------------- /week-4/d2-es6-classes/practices/03-inheritance/test/student-spec.js: -------------------------------------------------------------------------------- 1 | const chai = require("chai"); 2 | const spies = require("chai-spies"); 3 | chai.use(spies); 4 | const expect = chai.expect; 5 | 6 | const Student = require("../classes/student"); 7 | 8 | describe("Student class", () => { 9 | let student1; 10 | 11 | beforeEach(() => { 12 | student1 = new Student("billy", "johnson", "software-development", 3.2); 13 | }); 14 | describe("Student constructor", () => { 15 | it("should set the firstName property", () => { 16 | expect(student1).to.have.property("firstName"); 17 | expect(student1.firstName).to.eql("billy"); 18 | }); 19 | 20 | it("should set the lastName property", () => { 21 | expect(student1).to.have.property("lastName"); 22 | expect(student1.lastName).to.eql("johnson"); 23 | }); 24 | 25 | it("should set the major property", () => { 26 | expect(student1).to.have.property("major"); 27 | expect(student1.major).to.eql("software-development"); 28 | }); 29 | 30 | it("should set the GPA property", () => { 31 | expect(student1).to.have.property("GPA"); 32 | expect(student1.GPA).to.eql(3.2); 33 | }); 34 | }); 35 | 36 | describe("compareGPA static method", () => { 37 | it("should return the student with the highest GPA", () => { 38 | let student2 = new Student("sarah", "smith", "basket-weaving", 3.7); 39 | expect(Student.compareGPA(student1, student2)).to.eql( 40 | "sarah smith has the higher GPA." 41 | ); 42 | }); 43 | }); 44 | }); -------------------------------------------------------------------------------- /week-6/d2-binary-search-merge-quicksort/practices/02-merge-sort/test/merge-sort-specs.js: -------------------------------------------------------------------------------- 1 | const { expect } = require('chai'); 2 | 3 | const chai = require('chai'); 4 | const spies = require('chai-spies'); 5 | 6 | chai.use(spies); 7 | 8 | const [merge, mergeSort] = require("../merge-sort.js"); 9 | 10 | describe ('Better Sorting Algorithms', function () { 11 | 12 | let arr; 13 | let consoleSpy; 14 | 15 | beforeEach(function () { 16 | 17 | consoleSpy = chai.spy.on(console, 'log'); 18 | 19 | arr = [2,4,6,8,1,3,5,7,9]; 20 | }); 21 | 22 | afterEach(() => { 23 | chai.spy.restore(console, 'log'); 24 | }); 25 | 26 | 27 | it('merges two sorted arrays', function () { 28 | 29 | const arr1 = [1, 3, 5, 7, 9]; 30 | const arr2 = [2, 4, 6, 8, 10]; 31 | 32 | const merged = merge(arr1, arr2); 33 | 34 | expect(merged).to.deep.equal([1,2,3,4,5,6,7,8,9,10]); 35 | 36 | }); 37 | 38 | 39 | it('merges two sorted arrays of different lengths', function () { 40 | 41 | const arr1 = [1, 3]; 42 | const arr2 = [2, 4, 6, 8, 10]; 43 | 44 | expect(merge(arr1, arr2)).to.deep.equal([1,2,3,4,6,8,10]); 45 | 46 | const arr3 = [3, 6, 9]; 47 | const arr4 = []; 48 | 49 | expect(merge(arr3, arr4)).to.deep.equal([3, 6, 9]); 50 | 51 | }); 52 | 53 | 54 | 55 | it('performs a out-of-place merge sort', function () { 56 | 57 | let newArr = mergeSort(arr); 58 | 59 | expect(newArr).to.deep.equal([1,2,3,4,5,6,7,8,9]); 60 | expect(arr).to.deep.equal([2,4,6,8,1,3,5,7,9]); 61 | 62 | }); 63 | 64 | 65 | }); 66 | 67 | -------------------------------------------------------------------------------- /week-4/d3-context-bind-call-apply/practices/04-context-arrow-functions/review.js: -------------------------------------------------------------------------------- 1 | // Convert restSum into a multi-line fat-arrow function 2 | const restSum = function(...otherNums) { 3 | let sum = otherNums.reduce((acc, el) => (acc += el)); 4 | return sum; 5 | }; 6 | 7 | console.log('restSum output:'); 8 | console.log(restSum(1, 2, 3)); // 6 9 | 10 | // Convert getFullName into a one-liner fat-arrow function with implicit return 11 | // const getFullName = function(person) { 12 | // person.firstName + " " + person.lastName; 13 | // }; 14 | 15 | const getFullName = function(person) { 16 | return person.firstName + " " + person.lastName 17 | }; 18 | 19 | class Person { 20 | constructor(firstName, lastName) { 21 | this.firstName = firstName; 22 | this.lastName = lastName; 23 | } 24 | } 25 | 26 | console.log('getFullName output:'); 27 | console.log(getFullName(new Person("Elle", "Woods"))); // Elle Woods 28 | 29 | // Convert addFive into a one-liner fat-arrow function with implicit return 30 | const addFive = function(num){ 31 | num + 5 32 | }; 33 | 34 | console.log('addFive output:'); 35 | console.log(addFive(3)); // 8 36 | 37 | // Convert coupon and the function it returns into fat-arrow functions 38 | function coupon(discount) { 39 | return function(prices) { 40 | return prices.map((price) => (price -= price * discount)); 41 | }; 42 | } 43 | 44 | console.log('coupon output:'); 45 | console.log(coupon(0.5)([10, 6, 3, 9])); // [ 5, 3, 1.5, 4.5 ] 46 | 47 | // Challenge: Can you define the coupon function and its returned function in 48 | // one line? -------------------------------------------------------------------------------- /week-4/d5-es5-class-syntax/practices/01-custom-error-types/test/validation-error-spec.js: -------------------------------------------------------------------------------- 1 | const chai = require("chai"); 2 | const expect = chai.expect; 3 | 4 | const spies = require('chai-spies'); 5 | chai.use(spies); 6 | 7 | const ValidationError = require('../error-types/validation-error'); 8 | 9 | describe("ValidationError", () => { 10 | it("should be a child class of Error", () => { 11 | expect(ValidationError.prototype instanceof Error).to.be.true; 12 | }); 13 | 14 | describe("constructor(message)", () => { 15 | it("should set a name property of 'ValidationError'", () => { 16 | expect(new ValidationError().name).to.eq("ValidationError"); 17 | }); 18 | 19 | it("should capture the stack trace correctly", () => { 20 | const traceSpy = chai.spy.on(Error, 'captureStackTrace'); 21 | new ValidationError(); 22 | expect(traceSpy).to.have.been.called.once; 23 | chai.spy.restore(Error); 24 | }); 25 | 26 | context("when a message is passed in", () => { 27 | it("should set the message of the error to be the passed-in message", () => { 28 | const error = new ValidationError("Password fields do not match"); 29 | expect(error.message).to.eq("Password fields do not match"); 30 | }); 31 | }); 32 | 33 | context("when a message is NOT passed in", () => { 34 | it("should set the default message of the error to be 'Invalid input'", () => { 35 | const error = new ValidationError(); 36 | expect(error.message).to.eq("Invalid input"); 37 | }); 38 | }); 39 | }); 40 | }); -------------------------------------------------------------------------------- /week-5/d4-hash-tables-and-sets/practices/01-hash-tables/README-pt1.md: -------------------------------------------------------------------------------- 1 | # Hash Table Practice Part 1 2 | 3 | In this four-part exercise, you will start implementing a hash table that 4 | handles hash collisions with linked list chaining. 5 | 6 | ## Setup 7 | 8 | 1. Download the starter at the bottom of this page 9 | 2. Install all packages with `npm install` 10 | 3. Run specs with `npm test test/hash-table-pt1-spec.js` 11 | 12 | ## Hash table constructor 13 | 14 | Start by implementing the constructor for the hash table. 15 | 16 | The hash table should count the key/value pairs stored in the table and 17 | contain a data storage array filled with `null` values. 18 | 19 | Run specs with `npm test test/hash-table-pt1-spec.js` 20 | 21 | ## Hash methods 22 | 23 | In order to test your hash table predictably, you will be implementing hashing 24 | methods. 25 | 26 | `hash(key)` takes in a string key and returns the first 8 characters of 27 | its sha256 hash as an integer. 28 | 29 | Example: `hash('ABC')` will calculate the `sha256('ABC')`, then convert 30 | the first 8 characters to the integer `3050570844`. 31 | 32 | > Hint: The `sha256` function returns a string containing 64 hexadecimal 33 | > characters. How can you convert the first 8 characters of that string into 34 | > an integer? 35 | 36 | `hashMod(key)` takes in a string key and return the hash modulo the capacity 37 | of the data array. 38 | 39 | Example: `hashMod('ABC')` in a hash table with 10 buckets would return 40 | 3050570844 modulo 10, or `4`. 41 | 42 | Read the specs in `test/hash-table-pt1-spec.js` for more details. 43 | -------------------------------------------------------------------------------- /week-4/d3-context-bind-call-apply/notes/demo.js: -------------------------------------------------------------------------------- 1 | 2 | // class Fruit { 3 | // constructor(name) { 4 | // this.name = name; 5 | // } 6 | 7 | // eat = () => { 8 | // console.log(`${this.name} has a bite mark`); 9 | // }; 10 | // } 11 | 12 | // const apple = new Fruit("apple"); 13 | // const eat = apple.eat; 14 | // setTimeout(eat, 1000); 15 | 16 | /******************** */ 17 | 18 | // class Fruit { 19 | // constructor(name) { 20 | // this.name = name; 21 | // } 22 | 23 | // eat = () => { 24 | // console.log(`${this.name} has a bite mark`); 25 | // }; 26 | // } 27 | 28 | // const apple = new Fruit("apple"); 29 | // const eat = apple.eat; 30 | // eat(); 31 | 32 | 33 | /**************** */ 34 | 35 | // function greeting(...messages) { 36 | // return messages.map((message) => { 37 | // return `${this.firstName} says ${message}`; 38 | // }); 39 | // } 40 | 41 | // const derek = { 42 | // firstName: "Derek", 43 | // }; 44 | 45 | // const derekMessages = greeting.bind(derek, "Hello class!"); 46 | // console.log(derekMessages("Goodbye class!")); 47 | 48 | 49 | /***************** */ 50 | 51 | // const sum = (...nums) => { 52 | // nums.reduce((acc, num) => acc + num); 53 | // }; 54 | 55 | // console.log(sum(1, 2, 3)); 56 | 57 | /************* */ 58 | 59 | // const sum = (...nums) => { 60 | // return nums.reduce((acc, num) => acc + num); 61 | // }; 62 | 63 | // console.log(sum(1, 2, 3)); 64 | 65 | /******************* */ 66 | 67 | const sum = (...nums) => { 68 | return nums.reduce((acc, num) => acc + num); 69 | }; 70 | 71 | console.log(sum(1, 2, 3)); -------------------------------------------------------------------------------- /week-5/d2-binary-hexa-ascii-memory-arrays/practices/01-binary-hexa-conversion-functions/binary-hexa-conversion-functions.js: -------------------------------------------------------------------------------- 1 | /* 2 | Implement these functions to convert values into the appropriate number base. 3 | Consult documentation on how to utilize the following methods: 4 | parseInt() 5 | toString() 6 | */ 7 | 8 | /* Base 10 to base 2 */ 9 | function decimalToBinary(blob) { 10 | // Your code here 11 | } 12 | 13 | /* Base 10 to base 16 */ 14 | function decimalToHexadecimal(blob) { 15 | // Your code here 16 | } 17 | 18 | /* Base 2 to base 10 */ 19 | function binaryToDecimal(blob) { 20 | // Your code here 21 | } 22 | 23 | /* Base 16 to base 10 */ 24 | function hexadecimalToDecimal(blob) { 25 | // Your code here 26 | } 27 | 28 | // console.log('Decimal to binary:') 29 | // console.log(decimalToBinary(13)) // '0b1101' 30 | // console.log(decimalToBinary(72)) // '0b1001000' 31 | // console.log('') 32 | 33 | // console.log('Decimal to hexadecimal:') 34 | // console.log(decimalToHexadecimal(9)) // '0x9' 35 | // console.log(decimalToHexadecimal(32)) // '0x20' 36 | // console.log('') 37 | 38 | // console.log('Binary to decimal:') 39 | // console.log(binaryToDecimal('0b0101')) // 5 40 | // console.log(binaryToDecimal('0b10001000')) // 136 41 | // console.log('') 42 | 43 | // console.log('Hexadecimal to decimal:') 44 | // console.log(hexadecimalToDecimal('0x51')) // 81 45 | // console.log(hexadecimalToDecimal('0x10ff')) // 4351 46 | 47 | 48 | module.exports = { 49 | decimalToBinary, 50 | decimalToHexadecimal, 51 | binaryToDecimal, 52 | hexadecimalToDecimal 53 | } 54 | -------------------------------------------------------------------------------- /week-4/d2-es6-classes/practices/03-inheritance/test/teacher-spec.js: -------------------------------------------------------------------------------- 1 | const chai = require("chai"); 2 | const spies = require("chai-spies"); 3 | chai.use(spies); 4 | const expect = chai.expect; 5 | 6 | const Teacher = require("../classes/teacher"); 7 | 8 | describe("Teacher class", () => { 9 | let teacher1; 10 | let teacher2; 11 | 12 | beforeEach(() => { 13 | teacher1 = new Teacher("susan", "jones", "biology", 5); 14 | teacher2 = new Teacher("bobby", "roberts", "math", 15); 15 | }); 16 | 17 | describe("Teacher constructor", () => { 18 | it("should set the firstName property", () => { 19 | expect(teacher1).to.have.property("firstName"); 20 | expect(teacher1.firstName).to.eql("susan"); 21 | }); 22 | 23 | it("should set the lastName property", () => { 24 | expect(teacher1).to.have.property("lastName"); 25 | expect(teacher1.lastName).to.eql("jones"); 26 | }); 27 | 28 | it("should set the subject property", () => { 29 | expect(teacher1).to.have.property("subject"); 30 | expect(teacher1.subject).to.eql("biology"); 31 | }); 32 | 33 | it("should set the yearsOfExperience property", () => { 34 | expect(teacher1).to.have.property("yearsOfExperience"); 35 | expect(teacher1.yearsOfExperience).to.eql(5); 36 | }); 37 | }); 38 | 39 | describe("combinedYearsOfExperience static method", () => { 40 | it("should return the count of total combined yearsOfExperience of an array of teachers", () => { 41 | expect(Teacher.combinedYearsOfExperience([teacher1, teacher2])).to.eql( 42 | 20 43 | ); 44 | }); 45 | }); 46 | }); 47 | -------------------------------------------------------------------------------- /week-6/d2-binary-search-merge-quicksort/notes/quick-sort.js: -------------------------------------------------------------------------------- 1 | /* 2 | Just like Merge Sort, Quick Sort uses a divide and conquer strategy. The key 3 | ideas of Quick Sort are: 4 | 1. It is easy to sort elements of an array relative to a particular target 5 | value. 6 | 2. An array of 0 or 1 elements is already sorted 7 | 8 | 9 | There are some standard steps when implementing a quick sort algorithm: 10 | 1. choose an element called "the pivot", how that's done is up to the 11 | implementation 12 | 2. take two variables to point left and right of the list excluding pivot 13 | 3. left points to the low index 14 | 4. right points to the high 15 | 5. while value at left is less than pivot move right 16 | 6. while value at right is greater than pivot move left 17 | 7. if both step 5 and step 6 does not match swap left and right 18 | 8. if left ≥ right, the point where they met is new pivot 19 | 9. repeat, recursively calling this for smaller and smaller arrays 20 | 21 | 22 | */ 23 | function quickSort(array) { 24 | if (array.length <= 1) { 25 | //array of length = 0 || 1 is already sorted 26 | return array; 27 | } 28 | 29 | let pivot = array.shift(); //The element that we will use to create our left and right arrays 30 | let left = array.filter((el) => el < pivot); //elements less than the pivot 31 | let right = array.filter((el) => el >= pivot); //elements greater than or equal to the pivot 32 | 33 | let leftSorted = quickSort(left); //recursively call quickSort on each half 34 | let rightSorted = quickSort(right); 35 | 36 | return [...leftSorted, pivot, ...rightSorted]; //return the new sorted array 37 | } -------------------------------------------------------------------------------- /week-4/d5-es5-class-syntax/practices/02-es5-classes/README.md: -------------------------------------------------------------------------------- 1 | # Practice: ES5 Classes 2 | 3 | In this practice, you will use ES6 class syntax to define classes and 4 | monkey-patch an existing class. 5 | 6 | ## Set up 7 | 8 | Clone the starter from the **Download** link at the bottom of this page. 9 | 10 | Run `npm install` to install any dependencies. 11 | 12 | ## Phase 1: Refactor classes into ES5 class syntax 13 | 14 | Take a look at the __classes/dog.js__ file. The test specs for the `Dog` class 15 | in the __test/dog-spec.js__ file are already passing. Refactor the `Dog` class 16 | to use ES5 class syntax instead. Test your code to make sure it still works 17 | after the refactor by running the following command: 18 | 19 | ```shell 20 | npm test test/dog-spec.js 21 | ``` 22 | 23 | Take a look at the __classes/person.js__ file. The test specs for the `Person` 24 | class in the __test/person-spec.js__ file are already passing. Refactor the 25 | `Person` class to use ES5 class syntax instead. Test your code to make sure it 26 | still works after the refactor by running the following command: 27 | 28 | ```shell 29 | npm test test/person-spec.js 30 | ``` 31 | 32 | ## Phase 2: Monkey-patch the `Array` class 33 | 34 | Finally, take a look at the __classes/array.js__ file. Monkey-patch the `Array` 35 | class so that all the test specs in the __test/array-spec.js__ file pass. Run 36 | the test specs with the following command: 37 | 38 | ```shell 39 | npm test test/array-spec.js 40 | ``` 41 | 42 |
Hint: The method you are adding to the 43 | Array class tests if two arrays are deeply equal.
44 | -------------------------------------------------------------------------------- /week-5/d4-hash-tables-and-sets/notes/sets.md: -------------------------------------------------------------------------------- 1 | # Sets 2 | 3 | A set is an abstract data type that stores a collection of _unique_, unordered values. 4 | The unique part is important as a set can have no duplicate values. 5 | 6 | Being unordered is also important. Items are inserted into the set based on the hash valued index. 7 | 8 | A big benefit of using a set is that it has a lookup time, using the set.has() method, of O(1)! 9 | 10 | ** Sets are implemented using hash tables to achieve that O(1) search time complexity. 11 | 12 | Sets have an O(n) space complexity, despite the fact that they dynamically resize when the underlying array hits .7 load capacity. 13 | 14 | The use of sets is very niche, but are capable of massive performance gains when used appropriately. 15 | 16 | Javascript has a built in Set class. To instantiate a new set, you would do: 17 | 18 | ```js 19 | const set = new Set() 20 | ``` 21 | A set has access to certain methods and properties: 22 | 23 | ```js 24 | set.size //returns the number of values in the set 25 | set.has(val) //returns a boolean of whether that set contains a particular value 26 | set.add(val) //adds a new value to the set, utilizing hash table logic under the hood (hashing, modulo, etc.) 27 | set.clear() //removes all values in the set 28 | set.delete(val) //removes a specific value and returns a boolean of whether the removal was successful 29 | ``` 30 | 31 | Sets in javascript also have some iteration methods built in: 32 | - These include @@iterator, /values, values(), entries and forEach. Look these up on MDN for more info. 33 | https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set -------------------------------------------------------------------------------- /week-5/w5-review-guide/conversion-extra-practice/conversion-practice.js: -------------------------------------------------------------------------------- 1 | //Convert the following: _HINT_: to be best prepared to do this on the test, create functions to do this. 2 | 3 | //Hexadecimal to decimal: 4 | function hexToDec(hexStr) {} 5 | console.log(hexToDec("309")); // => 777 6 | /**************************** */ 7 | 8 | //Decimal to Binary: 9 | //5687 10 | function decToBin(decimal) {} 11 | console.log(decToBin(5687)); // => 1011000110111 12 | /***************************** */ 13 | 14 | //Binary to Decimal: 15 | //0b101101 16 | function binToDec(binaryBlob) {} 17 | console.log(binToDec(101101)); // => 45 18 | /****************************** */ 19 | 20 | //Decimal to Hexadecimal: 21 | //13453 22 | function decToHex(decimal) {} 23 | console.log(decToHex(13453)); // => 348d 24 | /****************************** */ 25 | 26 | //Hexadecimal to ASCII: 27 | function hexToASCII(hexStr) {} 28 | console.log(hexToASCII("736F667477617265")); // => software 29 | /******************************* */ 30 | 31 | //Binary to ASCII: 32 | function binToASCII(binaryBlob) {} 33 | console.log( 34 | binToASCII( 35 | "01101010 01100001 01110110 01100001 01110011 01100011 01110010 01101001 01110000 01110100" 36 | ) 37 | ); // => javascript 38 | /******************************** */ 39 | 40 | //ASCII to Binary: 41 | //'appacademy' 42 | function ASCIIToBin(ASCIIStr) {} 43 | console.log(ASCIIToBin("appacademy")); // => 01100001011100000111000001100001011000110110000101100100011001010110110101111001 44 | /********************************* */ 45 | 46 | //ASCII to Hexadecimal: 47 | //'badger' 48 | function ASCIIToHex(ASCIIStr) {} 49 | console.log(ASCIIToHex("badger")); // => 626164676572 50 | -------------------------------------------------------------------------------- /week-4/d2-es6-classes/practices/04-polymorphism/test/introduce-spec.js: -------------------------------------------------------------------------------- 1 | const chai = require("chai"); 2 | const expect = chai.expect; 3 | 4 | const spies = require("chai-spies"); 5 | chai.use(spies); 6 | 7 | const Person = require("../classes/person"); 8 | const Student = require("../classes/student"); 9 | const Teacher = require("../classes/teacher"); 10 | 11 | describe("Person class", () => { 12 | let person1; 13 | 14 | beforeEach(() => { 15 | person1 = new Person("kristen", "chauncey", 38); 16 | }); 17 | 18 | describe("Person instance method introduce", () => { 19 | it("should still behave the same as before", () => { 20 | expect(person1.introduce()).to.eql(`Hi, I'm kristen chauncey, and I'm 38 years old.`); 21 | }); 22 | }); 23 | }); 24 | 25 | describe("Student class", () => { 26 | let student1; 27 | 28 | beforeEach(() => { 29 | student1 = new Student("billy", "johnson", "software-development", 3.2); 30 | }); 31 | 32 | describe("Student instance method introduce", () => { 33 | it("should call the unique introduce method for Student", () => { 34 | expect(student1.introduce()).to.eql('Hello. I am billy johnson, and I study software-development.') 35 | }); 36 | }); 37 | }); 38 | 39 | describe("Teacher class", () => { 40 | let teacher1; 41 | 42 | beforeEach(() => { 43 | teacher1 = new Teacher("susan", "jones", "biology", 5); 44 | }); 45 | 46 | describe("Teacher instance method introduce", () => { 47 | it("should call the unique introduce method for Student", () => { 48 | expect(teacher1.introduce()).to.eql('Hello. I am susan jones, and I have been teaching biology for 5 years.') 49 | }); 50 | }); 51 | }); 52 | -------------------------------------------------------------------------------- /week-5/d4-hash-tables-and-sets/practices/01-hash-tables/README-pt4.md: -------------------------------------------------------------------------------- 1 | # Hash Table Practice Part 4 2 | 3 | In this four-part exercise, you will start implementing a hash table that 4 | handles hash collisions with linked list chaining. 5 | 6 | ## Setup 7 | 8 | 1. Continue working in the same starter as part 1, 2 and 3 9 | 2. Run specs with `npm test test/hash-table-pt4-spec.js` 10 | 11 | ## Part 4: Hash table insert with hash and key collisions 12 | 13 | Finally, you will write a *complete* insert function. It will handle hash 14 | collisions with linked list chaining as in part 3, AND, if the same key is 15 | inserted, but with a different value, the old value is overwritten by the new 16 | value. This functionality will enable us to "update" values that share 17 | the same key in a `KeyValuePair`. Note this is not the same as a hash 18 | collision! 19 | 20 | `insert(key, value)` will create a new `KeyValuePair()` with the input key and 21 | value and store it in the data bucket location returned by hashMod(key)`. 22 | 23 | If that bucket is already occupied, it will insert the new `KeyValuePair` to 24 | the head of the linked list in the bucket. 25 | 26 | If the new `KeyValuePair` contains the same `key` as a pair already in the hash 27 | table, the method will overwrite the old `value` with the one from the newly 28 | inserted pair. 29 | 30 | Note that the test specs successfully inserts 3 key/value pairs into a hash 31 | table with a capacity of 2. Linked list chaining allows the linked list to 32 | fill past capacity at the cost of performance. 33 | 34 | The bucket order of keys is reliant on a valid hash function from part 1. 35 | 36 | Read the specs in `test/hash-table-pt4-spec.js` for more details. 37 | -------------------------------------------------------------------------------- /week-4/d2-es6-classes/notes/import-export/commonJS.md: -------------------------------------------------------------------------------- 1 | Overview 2 | 3 | - up until now we've put all our code in single JS file 4 | - as code base gets larger we'll want to break our code up into multiple files 5 | - each file containing a logical unit of code that defines a module. 6 | 7 | Modules 8 | 9 | - a module is just a javascript file 10 | - local module: defined within your project 11 | - core modules: native modules contained within Node.js 12 | - don't have to npm install 13 | - ex: `path`, `readline`, `fs` 14 | - third party modules: imported using npm 15 | 16 | Module systems 17 | 18 | - recent node versions contain two different systems 19 | 1. CommonJS (legacy system) 20 | 2. ES Modules (newer system) 21 | - conceptually similar 22 | - syntax/implementation details differ 23 | 24 | The Module Object 25 | 26 | - each module in node has access to a `module` object 27 | - represents current module 28 | - contains number of properties with info about current module 29 | 30 | The `module.exports` Property 31 | 32 | - object used to export items from the module 33 | 34 | To Export a Single Item: 35 | 36 | - set `module.exports` equal to that item 37 | - OR 38 | - define property for that item on the `module.exports` obj 39 | 40 | 41 | Common JS Modules: 42 | ```js 43 | // animal.js 44 | class Dog {} 45 | class Cat {} 46 | module.exports = { Cat, Dog } 47 | // or 48 | // module.exports = { Cat: Cat, Dog: Dog } 49 | // or 50 | // module.exports.Cat = Cat; 51 | // module.exports.Dog = Dog; 52 | 53 | 54 | // shelter.js 55 | class Shelter {} 56 | module.exports = Shelter 57 | 58 | 59 | 60 | // index.js 61 | const { Cat, Dog } = require('./animal'); 62 | const Shelter = require('./shelter') 63 | 64 | ``` 65 | 66 | -------------------------------------------------------------------------------- /week-5/d1-big-o-arrays/extra-practice/big-o-intro-extra-practice/solutions/01-big-octopus.js: -------------------------------------------------------------------------------- 1 | // O(n^2) time 2 | // O(1) space 3 | function quadraticBiggestFish(fishes) { 4 | for (let i = 0; i < fishes.length; i++) { 5 | let fish1 = fishes[i]; 6 | let maxLength = true; 7 | for (let j = i; j < fishes.length; j++) { 8 | let fish2 = fishes[j]; 9 | if (fish2.length > fish1.length) maxLength = false; 10 | } 11 | if (maxLength) return fish1; 12 | } 13 | } 14 | 15 | // O(n log n) time 16 | // O(1) space 17 | function nlognBiggestFish(fishes) { 18 | // sort the array longest to shortest 19 | fishes.sort((a, b) => b.length - a.length); 20 | //return the first element 21 | return fishes[0]; 22 | } 23 | 24 | // O(n) time 25 | // O(1) space 26 | function linearBiggestFish(fishes) { 27 | let biggestFish = fishes[0]; 28 | 29 | for (let fish of fishes) { 30 | if (fish.length > biggestFish.length) biggestFish = fish; 31 | } 32 | 33 | return biggestFish; 34 | } 35 | 36 | // linear octopus dance 37 | // O(n) time 38 | const tilesArray = [ 39 | "up", 40 | "right-up", 41 | "right", 42 | "right-down", 43 | "down", 44 | "left-down", 45 | "left", 46 | "left-up", 47 | ]; 48 | 49 | function slowDance(direction, tilesArray) { 50 | for (let i = 0; i < tilesArray.length; i++) { 51 | let tile = tilesArray[i]; 52 | if (tile == direction) return i; 53 | } 54 | } 55 | 56 | // constant octopus dance 57 | //use an object for constant lookup 58 | // O(1) time 59 | const tilesObj = { 60 | up: 0, 61 | "right-up": 1, 62 | right: 2, 63 | "right-down": 3, 64 | down: 4, 65 | "left-down": 5, 66 | left: 6, 67 | "left-up": 7, 68 | }; 69 | 70 | function fastDance(direction, tilesObj) { 71 | return tilesObj[direction]; 72 | } 73 | -------------------------------------------------------------------------------- /week-4/d5-es5-class-syntax/practices/01-custom-error-types/test/maximum-length-exceeded-error-spec.js: -------------------------------------------------------------------------------- 1 | const chai = require("chai"); 2 | const expect = chai.expect; 3 | 4 | const spies = require('chai-spies'); 5 | chai.use(spies); 6 | 7 | const ValidationError = require('../error-types/validation-error'); 8 | const MaximumLengthExceededError = require('../error-types/maximum-length-exceeded-error'); 9 | 10 | describe("MaximumLengthExceededError", () => { 11 | it("should be a child class of ValidationError", () => { 12 | expect(MaximumLengthExceededError.prototype instanceof ValidationError).to.be.true; 13 | }); 14 | 15 | describe("constructor(excessLength)", () => { 16 | it("should set a name property of 'MaximumLengthExceededError'", () => { 17 | expect(new MaximumLengthExceededError().name).to.eq("MaximumLengthExceededError"); 18 | }); 19 | 20 | it("should capture the stack trace correctly", () => { 21 | const traceSpy = chai.spy.on(Error, 'captureStackTrace'); 22 | new MaximumLengthExceededError(); 23 | expect(traceSpy).to.have.been.called.once; 24 | chai.spy.restore(Error); 25 | }); 26 | 27 | context("when an excessLength is passed in", () => { 28 | it("should set the message of the error to be 'Maximum length exceeded by ${excessLength}'", () => { 29 | const error = new MaximumLengthExceededError(5); 30 | expect(error.message).to.eq('Maximum length exceeded by 5'); 31 | }); 32 | }); 33 | 34 | context("when an excessLength is NOT passed in", () => { 35 | it("should set the message of the error to be 'Maximum length exceeded'", () => { 36 | const error = new MaximumLengthExceededError(); 37 | expect(error.message).to.eq('Maximum length exceeded'); 38 | }); 39 | }); 40 | }); 41 | }); -------------------------------------------------------------------------------- /week-6/d1-sorting-bubble-insertion-selection/practices/02-insertion-sort/insertion-sort.js: -------------------------------------------------------------------------------- 1 | // Insertion Sort out-of-place 2 | // Do not modify the original array 3 | function insertionSort(arr) { 4 | /* 5 | Pseudocode: 6 | 7 | Copy the original array 8 | Create an array to store the sorted values 9 | While the array is not empty: 10 | - make sure you have a console.log(sorted.join(',')) as your first line in the while loop 11 | - Pop a value from the array 12 | - Create a new spot at the end of the array with null to help with comparisons 13 | - Walk through the sorted array in reverse order 14 | - Check if the value to the left is smaller than the new value 15 | - If so, you've reached the insertion point so exit the loop 16 | - If not shift the value to the right by 1 and continue 17 | - Insert the unsorted value at the break point 18 | Return the sorted array 19 | */ 20 | 21 | // Your code here 22 | } 23 | 24 | // In-place Insertion Sort 25 | // Mutates the original array 26 | function insertionSortInPlace(arr) { 27 | /* 28 | Pseudocode: 29 | 30 | Set a pointer dividing the array into sorted and unsorted halves 31 | Repeat while the unsorted half is not empty: 32 | - make sure you have a console.log(sorted.join(',')) as your first line in the while loop 33 | - Grab the first value from the unsorted half 34 | - For each value starting from the divider, 35 | - Check if the value to the left is smaller than the unsorted value 36 | - If so, you've reached the insertion point so exit the loop 37 | - If not shift the value to the right by 1 and continue 38 | - Insert the unsorted value at the break point 39 | - Increment the dividing pointer and repeat 40 | Return the mutated array 41 | */ 42 | 43 | // Your code here 44 | } 45 | 46 | module.exports = [insertionSort, insertionSortInPlace]; 47 | -------------------------------------------------------------------------------- /week-6/d2-binary-search-merge-quicksort/notes/binarySearch.js: -------------------------------------------------------------------------------- 1 | /* 2 | Binary Search: 3 | -Binary Search utilizes the divide and conquer approach. 4 | -You've already used this without even knowing... 5 | ex: Phonebooks, dictionaries, etc. 6 | Binary search method first looks at the midpoint of a 7 | SORTED array, and then checks to see if that element is 8 | greater than, less than, or equal to the element you are looking for. 9 | 10 | IT ONLY WORKS WITH SORTED ARRAYS, so it is often needed to have a 11 | sorting function that can quickly sort your array if it is not presorted 12 | */ 13 | 14 | //quick way of sorting arrays in Javascript 15 | 16 | let array = [5, 28, 98, 13, 4, 87, 45, 2]; 17 | array.sort(function (a, b) { 18 | if (a > b) return 1; 19 | if (a < b) return -1; 20 | return 0; 21 | }); 22 | console.log(array); 23 | 24 | 25 | function binarySearch(arr, target) { 26 | // Set integers pointing to the high and low range of possible indices 27 | let lo = 0; 28 | let hi = arr.length - 1; 29 | 30 | // While high and low indices do not overlap... 31 | while (lo <= hi) { 32 | // Find the midpoint between high and low indices 33 | let mid = Math.floor((hi + lo) / 2); 34 | 35 | // Compare the target value to the midpoint value 36 | 37 | // If the target equals the midpoint... 38 | if (target === arr[mid]) { 39 | // Return true 40 | return true; 41 | // If the target is higher than the midpoint... 42 | } else if (target > arr[mid]) { 43 | // Move the low pointer to midpoint + 1 44 | lo = mid + 1; 45 | // If the target is less than the midpoint... 46 | } else { 47 | // Move the high pointer to midpoint - 1 48 | hi = mid - 1; 49 | } 50 | } 51 | 52 | // Return false if the loop exits with overlapping pointers 53 | return false; 54 | } 55 | 56 | console.log(binarySearch(array, 13)); -------------------------------------------------------------------------------- /week-5/d4-hash-tables-and-sets/practices/01-hash-tables/test/hash-table-pt2-spec.js: -------------------------------------------------------------------------------- 1 | const { expect } = require('chai'); 2 | 3 | const HashTable = require('../hash-table.js'); 4 | 5 | 6 | describe('Hash table insert no collision handling', () => { 7 | 8 | let hashTable; 9 | 10 | beforeEach(function () { 11 | 12 | hashTable = new HashTable(2); 13 | 14 | }); 15 | 16 | it('insert adds key-value pair that does not cause collisions', () => { 17 | 18 | hashTable.insertNoCollisions("key-1", "val-1"); 19 | hashTable.insertNoCollisions("key-2", "val-2"); 20 | 21 | expect(hashTable.count).to.equal(2); 22 | expect(hashTable.capacity).to.equal(2); 23 | expect(hashTable.data.length).to.equal(2); 24 | 25 | const pairA = hashTable.data[0]; 26 | const pairB = hashTable.data[1]; 27 | 28 | expect(pairA.key).to.equal("key-1"); 29 | expect(pairA.value).to.equal("val-1"); 30 | 31 | expect(pairB.key).to.equal("key-2"); 32 | expect(pairB.value).to.equal("val-2"); 33 | 34 | }); 35 | 36 | it('insert throws an error if hash collision occurs', () => { 37 | 38 | hashTable.insertNoCollisions("key-1", "val-1"); 39 | hashTable.insertNoCollisions("key-2", "val-2"); 40 | 41 | const errorMessage = 'hash collision or same key/value pair already exists!' 42 | // a hash collision 43 | expect(() => hashTable.insertNoCollisions("key-3", "val-3")).to.throw(Error, errorMessage); 44 | 45 | }); 46 | 47 | it('insert throws an error if same key/value pair exists', () => { 48 | 49 | hashTable.insertNoCollisions("key-1", "val-1"); 50 | hashTable.insertNoCollisions("key-2", "val-2"); 51 | 52 | const errorMessage = 'hash collision or same key/value pair already exists!' 53 | // a same key/pair insert 54 | expect(() => hashTable.insertNoCollisions("key-2", "val-2")).to.throw(Error, errorMessage); 55 | 56 | }); 57 | 58 | }); 59 | -------------------------------------------------------------------------------- /week-6/d3-binary-search-trees/notes/tree-traversal.md: -------------------------------------------------------------------------------- 1 | ## Breadth-first traversal: 2 | 3 | Breadth first traversal works by traveling as deep as possible down each branch 4 | of a tree before moving to the next. 5 | 6 | Breadth-first traversal cannot be implemented using recursion. It is best implemented using a queue: 7 | 8 | Put the starting node in a queue 9 | While the queue is not empty, repeat steps 3-4 10 | Dequeue a node and print it 11 | Put all of the node's children in the back of the queue 12 | 13 | ```js 14 | function breadthFirstTraversal(root) { 15 | 16 | // Put the starting node in a queue 17 | const queue = new Queue(); 18 | queue.enqueue(root); 19 | 20 | // While the queue is not empty 21 | while (queue.size > 0) { 22 | 23 | // Dequeue a node and print it 24 | let node = queue.dequeue(); 25 | console.log(node.value); 26 | 27 | // Put all of the node's children in the back of the queue 28 | queue.enqueue(node.left); 29 | queue.enqueue(node.right); 30 | } 31 | } 32 | ``` 33 | 34 | ## Depth first traversal: 35 | 36 | Depth first traversal works very similar to breadth first, but we use a stack instead (think about FIFO vs LIFO): 37 | 38 | Put the starting node on a STACK 39 | While the STACK is not empty, repeat steps 3-4 40 | POP a node and print it 41 | Put all of the node's children on the TOP of the STACK 42 | 43 | ```js 44 | function depthFirstTraversal(root) { 45 | 46 | // Put the starting node on a stack 47 | const stack = []; 48 | stack.push(root); 49 | 50 | // While the stack is not empty 51 | while (stack.length > 0) { 52 | 53 | // Pop a node and print it 54 | let node = stack.pop(); 55 | console.log(node.value); 56 | 57 | // Put all of the node's children on the top of the stack 58 | stack.push(node.right); 59 | stack.push(node.left); 60 | } 61 | } 62 | ``` -------------------------------------------------------------------------------- /week-6/d1-sorting-bubble-insertion-selection/notes/insertion.js: -------------------------------------------------------------------------------- 1 | /* 2 | Insertion Sort works similar to Selection Sort in that it gradually builds up a 3 | larger and larger sorted region at the left-most end of the array. However, they 4 | differ in that insertion sort focuses on sorting each element in the order they 5 | appear from left to right, regardless of their value, and inserting them into 6 | the most appropriate position in the already sorted region. 7 | 8 | Steps of Insertion Sort: 9 | 1. If it is the first element, it is already sorted. return 1; 10 | 2. Pick next element 11 | 3. Compare with all elements in the sorted sub-list 12 | 4. Shift all the elements in the sorted sub-list that is greater than the value 13 | to be sorted 14 | 5. Insert the value 15 | 6. Repeat until list is sorted 16 | */ 17 | 18 | //This algorithm does not require the swap function we have used previously. 19 | 20 | function insertionSort(arr) { 21 | // the `i` loop will iterate through every element of the array we begin at i 22 | // = 1, because we can consider the first element of the array as a trivially 23 | // sorted region of only one element insertion sort allows us to insert new 24 | // elements anywhere within the sorted region 25 | for (let i = 1; i < arr.length; i++) { 26 | // grab the first element of the unsorted region 27 | let currElement = arr[i]; 28 | 29 | // the `j` loop will iterate left through the sorted region, looking for a 30 | // legal spot to insert currElement 31 | for (var j = i - 1; j >= 0 && currElement < arr[j]; j--) { 32 | // keep moving left while currElement is less than the j-th element 33 | 34 | arr[j + 1] = arr[j]; 35 | // the line above will move the j-th element to the right, leaving a gap 36 | // to potentially insert currElement 37 | } 38 | // insert currElement into that gap 39 | arr[j + 1] = currElement; 40 | } 41 | return arr; 42 | } -------------------------------------------------------------------------------- /week-5/d2-binary-hexa-ascii-memory-arrays/practices/01-binary-hexa-conversion-functions/README.md: -------------------------------------------------------------------------------- 1 | # Practice: Binary and Hexadecimal Conversion Functions 2 | 3 | In this practice you will use the JavaScript built-in functions, `parseInt()` 4 | and `toString()` to convert number bases of decimal, binary and hexadecimal. 5 | 6 | ## Set up 7 | 8 | - Download the starter at the bottom of this page. 9 | - Run `npm install` to install dependencies. 10 | - Run `npm test` to run specs. 11 | - Uncomment local specs to run local tests. 12 | 13 | ## Instructions 14 | 15 | Expect to utilize documentation to improve your understanding of these methods: 16 | - [`parseInt()` documentation][parseint-mdn] 17 | - [`toString()` documentation][tostring-mdn] 18 | 19 | Use these built-in JavaScript functions to implement the following conversion 20 | functions: 21 | 22 | ### Using `toString()` 23 | 24 | - `decimalToBinary(blob)` 25 | - Takes in a decimal argument and returns the equivalent binary string 26 | formatted to include `0b` prefix. 27 | - `decimalToHexadecimal(blob)` 28 | - Takes in a decimal argument and returns the equivalent hexadecimal string 29 | formatted to include `0x` prefix. 30 | 31 | ### Using `parseInt()` 32 | 33 | - `binaryToDecimal(blob)` 34 | - Takes in a binary string argument and returns the equivalent decimal 35 | number. 36 | - `hexadecimalToDecimal(blob)` 37 | - Takes in a hexadecimal string argument and returns the equivalent decimal 38 | number. 39 | 40 | ## What you've learned 41 | 42 | You have learned how to use `parseInt()` and `toString()` to change number 43 | bases. You have converted between decimal and binary, and also between decimal and 44 | hexadecimal. 45 | 46 | [parseint-mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt 47 | [tostring-mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString 48 | -------------------------------------------------------------------------------- /week-5/d1-big-o-arrays/extra-practice/big-o-intro-extra-practice/solutions/04-execution-time-difference.js: -------------------------------------------------------------------------------- 1 | //O(n^2) quadratic time 2 | //O(n) linear space 3 | function myMin1a(list) { 4 | let minNum = null; 5 | 6 | for (let num1 of list) { 7 | dupList = list.slice(); 8 | dupList = dupList.filter((item) => item !== num1); 9 | if (dupList.every((item) => item > num1)) { 10 | minNum = num1; 11 | } 12 | } 13 | 14 | return minNum; 15 | } 16 | 17 | //O(n^2) quadratic time 18 | //O(1) constant space 19 | function myMin1b(list) { 20 | for (let i = 0; i < list.length; i++) { 21 | let num1 = list[i]; 22 | let min = true; 23 | for (let j = 0; j < list.length; j++) { 24 | let num2 = list[j]; 25 | if (i === j) continue; 26 | if (num2 < num1) min = false; 27 | } 28 | if (min) return num1; 29 | } 30 | } 31 | 32 | //O(n) linear time 33 | //O(1) constant space 34 | function myMin2(list) { 35 | let minNum = list[0]; 36 | 37 | list.forEach(function (num) { 38 | if (num < minNum) minNum = num; 39 | }); 40 | 41 | return minNum; 42 | } 43 | 44 | //O(n^3) cubic time 45 | //O(n^3) cubic space 46 | function largestContiguousSubsum1(array) { 47 | let subArrays = []; 48 | 49 | for (let i = 0; i < array.length; i++) { 50 | for (let j = i; j < array.length; j++) { 51 | subArrays.push(array.slice(i, j + 1)); 52 | } 53 | } 54 | 55 | let sumOfArrays = []; 56 | for (let elt of subArrays) { 57 | sumOfArrays.push(elt.reduce((a, b) => a + b)); 58 | } 59 | return Math.max(...sumOfArrays); 60 | } 61 | 62 | //O(n) linear time 63 | //O(1) constant space 64 | function largestContiguousSubsum2(array) { 65 | let largest = array[0]; 66 | let current = array[0]; 67 | 68 | for (let i = 1; i < array.length; i++) { 69 | if (current < 0) current = 0; 70 | current += array[i]; 71 | if (current > largest) largest = current; 72 | } 73 | 74 | return largest; 75 | } 76 | -------------------------------------------------------------------------------- /week-6/d2-binary-search-merge-quicksort/practices/01-binary-search/test/search-specs.js: -------------------------------------------------------------------------------- 1 | const { expect } = require('chai'); 2 | 3 | const [linearSearch, binarySearch] = require("../binary-search.js"); 4 | 5 | describe ('Search', function () { 6 | 7 | let arr; 8 | 9 | before(function () { 10 | 11 | arr = []; 12 | 13 | for (let i = 0 ; i < 1000000 ; i++) { 14 | arr.push(i); 15 | } 16 | 17 | }); 18 | 19 | it('performs a linear search', function () { 20 | 21 | expect(linearSearch(arr, 100)).to.equal(100); 22 | 23 | expect(linearSearch(arr, 1000000)).to.equal(-1); 24 | 25 | }); 26 | 27 | it('performs a binary search', function () { 28 | 29 | expect(binarySearch(arr, 100)).to.equal(100); 30 | 31 | expect(binarySearch(arr, 1000000)).to.equal(-1); 32 | 33 | }); 34 | 35 | it('performs at least 500 linear searches in under 1 second', function () { 36 | 37 | const timeout = 1000; 38 | let linearSearches = 0; 39 | let startTime = Date.now(); 40 | let i = 1; 41 | 42 | while (i < arr.length) { 43 | expect(linearSearch(arr, i)).to.equal(i); 44 | expect(linearSearch(arr, -i)).to.equal(-1); 45 | 46 | linearSearches += 2; 47 | 48 | if (Date.now() - startTime > timeout || linearSearches > 500) { 49 | break; 50 | } 51 | } 52 | 53 | expect(linearSearches).to.be.above(500); 54 | 55 | }); 56 | 57 | it('performs at least 100000 binary searches in under 1 second', function () { 58 | 59 | const timeout = 1000; 60 | let startTime = Date.now(); 61 | let i = 1; 62 | let binarySearches = 0; 63 | 64 | while (i < arr.length) { 65 | expect(binarySearch(arr, i)).to.equal(i); 66 | expect(binarySearch(arr, -i)).to.equal(-1); 67 | 68 | binarySearches += 2; 69 | 70 | if (Date.now() - startTime > timeout || binarySearches > 100000) { 71 | break; 72 | } 73 | } 74 | 75 | expect(binarySearches).to.be.above(100000); 76 | }); 77 | 78 | 79 | }); 80 | 81 | -------------------------------------------------------------------------------- /week-6/d2-binary-search-merge-quicksort/notes/merge-sort.js: -------------------------------------------------------------------------------- 1 | /* 2 | Merge sort is the first of the efficient algorithms you will learn. 3 | 4 | Merge sort operates with a much better time complexity than the more naive approaches we started with. 5 | 6 | The main ideas of merge sort are: 7 | 1. It is easy to merge elements of two sorted arrays into a single sorted array 8 | 2. You can consider an array containing only a single element as already sorted 9 | 3. You can also consider an empty array as sorted 10 | */ 11 | 12 | function merge(array1, array2) { 13 | let merged = []; 14 | 15 | // keep running while either array still contains elements 16 | while (array1.length || array2.length) { 17 | // if array1 is nonempty, take its the first element as ele1 otherwise 18 | // array1 is empty, so take Infinity as ele1 19 | let ele1 = array1.length ? array1[0] : Infinity; 20 | 21 | // do the same for array2, ele2 22 | let ele2 = array2.length ? array2[0] : Infinity; 23 | 24 | let next; 25 | // remove the smaller of the eles from it's array 26 | if (ele1 < ele2) { 27 | next = array1.shift(); 28 | } else { 29 | next = array2.shift(); 30 | } 31 | 32 | // and add that ele to the new array 33 | merged.push(next); 34 | } 35 | 36 | return merged; 37 | } 38 | 39 | //Now that we have the merge helper function, we can move on to the sorting 40 | //algorithm: 41 | 42 | function mergeSort(array) { 43 | if (array.length <= 1) { //if the array is either length = 1 || 0 44 | return array; //return the array because it is already sorted 45 | } 46 | 47 | let midIdx = Math.floor(array.length / 2); //find the middle index 48 | let leftHalf = array.slice(0, midIdx); //split the array in two using slice 49 | let rightHalf = array.slice(midIdx); 50 | 51 | let sortedLeft = mergeSort(leftHalf); //recursively call mergeSort on each half 52 | let sortedRight = mergeSort(rightHalf); 53 | 54 | return merge(sortedLeft, sortedRight); //use our helper function to merge the sorted halves 55 | } -------------------------------------------------------------------------------- /week-6/d1-sorting-bubble-insertion-selection/notes/selection-sort.js: -------------------------------------------------------------------------------- 1 | /* 2 | Selection sort works very similar to Bubble Sort, but it works on sending the 3 | smallest elements down to the beginning of the array instead of sending the 4 | largest elements up. For the same reasons as Bubble Sort, Selection Sort is not 5 | very efficient at all. 6 | 7 | The algorithm can be summarized as follows: 8 | 1. Set MIN to location 0. 9 | 2. Search the minimum element in the list. 10 | 3. Swap with value at location MIN 11 | 4. Increment MIN to point to next element 12 | 5. Repeat until list is sorted 13 | */ 14 | 15 | //Again, we will need to implement our swap function: 16 | function swap(arr, idx1, idx2) { 17 | let temp = arr[idx1]; 18 | arr[idx1] = arr[idx2]; 19 | arr[idx2] = temp; 20 | } 21 | 22 | /* 23 | In order to find MIN, we will need to search the array to find the minimum 24 | value: This COULD be done in isolation with the following function: function 25 | minValueIdx(arr) {let minIdx = 0; for(let j = 0; j < arr.length; j++) {if 26 | (arr[minIdx] > arr[j]) {minIdx = j; 27 | } 28 | } 29 | return minIdx 30 | } 31 | 32 | However, we can build this logic right into the algorithm for Selection Sort: 33 | */ 34 | 35 | function selectionSort(arr) { 36 | // the `i` loop will track the index that points to the first element of the 37 | // unsorted region: this means that the sorted region is everything left of 38 | // index i and the unsorted region is everything to the right of index i 39 | for (let i = 0; i < arr.length; i++) { 40 | let minIndex = i; 41 | 42 | // the `j` loop will iterate through the unsorted region and find the index 43 | // of the smallest element 44 | for (let j = i + 1; j < arr.length; j++) { 45 | if (arr[minIndex] > arr[j]) { 46 | minIndex = j; 47 | } 48 | } 49 | 50 | // after we find the minIndex in the unsorted region, swap that minIndex 51 | // with the first index of the unsorted region 52 | swap(arr, i, minIndex); 53 | } 54 | return arr; 55 | } 56 | 57 | -------------------------------------------------------------------------------- /week-6/d4-graphs/practices/02-social-graph-practice/README-pt2.md: -------------------------------------------------------------------------------- 1 | # Social Graph Practice Part 2 2 | 3 | In this practice, you will implement a social network using an adjacency list. 4 | This network will be "follow" based, similar to Twitter or Instagram. 5 | 6 | Your task is to implement the `SocialNetwork` class with the ability to add 7 | users, follow users, list a user's followers and those they are following, 8 | and recommend followers. 9 | 10 | *Note: As you work through this practice recall the new information we learned about adjacency lists and apply that to your strategies and solutions rather than taking an OOP approach. This will help you cement these new concepts into your knowledge base for practices and projects moving forward.* 11 | 12 | ## Directions 13 | 14 | 1. Continue working from the [starter] from part 1 15 | 2. Read the directions and test specs to understand the problem 16 | 3. Run tests with `npm test` 17 | 4. Implement code until tests are all passing 18 | 19 | ## Part 2: Recommended Follows 20 | 21 | Implement `getRecommendedFollows` which takes in a userID and an integer, 22 | degrees. This function returns an array containing a list of recommended 23 | users to follow. 24 | 25 | It finds recommendations by the follows of that user's follows. The distance the algorithm will search for recommended follows is represented by the `degrees` integer. 26 | 27 | * degrees = 1 -> Users your follows also follow 28 | * degrees = 2 -> Users your follows follows also follow 29 | * degrees = 3 -> Users your follows follows follows also follow 30 | 31 | For example: 32 | 33 | ```js 34 | socialNetwork.getFollows(1); // [2] 35 | socialNetwork.getFollows(2); // [3] 36 | socialNetwork.getFollows(3); // [4, 5] 37 | socialNetwork.getFollows(4); // [1, 2] 38 | socialNetwork.getFollows(5); // [6] 39 | 40 | socialNetwork.getRecommendedFollows(1, 1); // [3] 41 | socialNetwork.getRecommendedFollows(1, 2); // [3, 4, 5] 42 | socialNetwork.getRecommendedFollows(1, 3); // [3, 4, 5, 6] 43 | ``` 44 | 45 | 46 | [starter]: https://github.com/appacademy/practice-for-week-06-social-graph-practice -------------------------------------------------------------------------------- /week-6/d1-sorting-bubble-insertion-selection/notes/bubbleSort.js: -------------------------------------------------------------------------------- 1 | /* 2 | Bubble Sort is almost NEVER used because it is not efficient!! 3 | - Every movement of an item requires an individual pass through the array. 4 | 5 | Bubble Sort works by moving the SMALLEST elements to the beginning of the array. 6 | 7 | Bubble Sort manipulates the array by swapping the position of two elements. To 8 | implement Bubble Sort in JS, you'll need to perform this operation. It helps to 9 | have a function to do that. A key detail in this function is that you need an 10 | extra variable to store one of the elements since you will be overwriting them 11 | in the array:  12 | */ 13 | 14 | //swap function: 15 | function swap(array, idx1, idx2) { 16 | let temp = array[idx1]; // save a copy of the first value 17 | array[idx1] = array[idx2]; // overwrite the first value with the second value 18 | array[idx2] = temp; // overwrite the second value with the first value 19 | } 20 | //Note that the swap function does not create or return a new array. It mutates 21 | //the original array: 22 | let arr1 = [2, 8, 5, 2, 6]; 23 | swap(arr1, 1, 2); 24 | arr1; // => [ 2, 5, 8, 2, 6 ] 25 | 26 | 27 | //Implementing bubble sort: 28 | function bubbleSort(array) { 29 | // this variable will be used to track whether or not we 30 | // made a swap on the previous pass. If we did not make 31 | // any swap on the previous pass, then the array must 32 | // already be sorted 33 | let swapped = true; 34 | 35 | // this while will keep doing passes if a swap was made 36 | // on the previous pass 37 | while (swapped) { 38 | swapped = false; // reset swap to false 39 | 40 | // this for will perform a single pass 41 | for (let i = 0; i < array.length; i++) { 42 | // if the two value are not ordered... 43 | if (array[i] > array[i + 1]) { 44 | // swap the two values 45 | swap(array, i, i + 1); 46 | 47 | // since you made a swap, remember that you did so 48 | // b/c we should perform another pass after this one 49 | swapped = true; 50 | } 51 | } 52 | } 53 | 54 | return array; 55 | } -------------------------------------------------------------------------------- /week-4/d2-es6-classes/practices/03-inheritance/README.md: -------------------------------------------------------------------------------- 1 | # Practice: Inheritance 2 | 3 | **Inheritance** is a mechanism that passes traits of a parent class to its 4 | descendants, which helps prevents duplication of code. In this exercise, you 5 | will be implementing two classes that demonstrate class inheritance in 6 | JavaScript. 7 | 8 | ## Set up 9 | 10 | Clone the starter from the **Download** link at the bottom of this page. 11 | 12 | ## Directions 13 | 14 | Create the following child classes for the parent class of `Person`. 15 | 16 | ### `Student` class 17 | 18 | Implement the following in the __classes/student.js__ file. 19 | 20 | 1. Create a new `Student` class and have its `constructor` call the `super()`, 21 | passing the parameters needed for a `Person` and a `constructor` function 22 | that takes in additional parameters for their `major` subject and `GPA`. 23 | 2. Create a static method called `compareGPA` which will take in two `Student` 24 | instances as the first and second parameter and return a string comparing 25 | the `GPA`s return "`` `` has the higher GPA." If they're 26 | equal, return "Both students have the same GPA." 27 | 28 | Run the test specs in the __test/student-spec.js__ file to test that you 29 | have created the `Student` class correctly: 30 | 31 | ```shell 32 | npm test test/student-spec.js 33 | ``` 34 | 35 | ### `Teacher` class 36 | 37 | Implement the following in the __classes/teacher.js__ file. 38 | 39 | 1. Create a new `Teacher` class and have its `constructor` call the `super()`, 40 | passing parameters needed for a `Person` and a `constructor` function that 41 | takes in additional parameters for the `subject` they teach and their 42 | `yearsOfExperience`. 43 | 2. Create a static method called `combinedYearsOfExperience` that takes in an 44 | array of `Teacher` instances, `teachers`, as a parameter and returns the sum 45 | of the `yearsOfExperience` of all `teachers`. 46 | 47 | Run the test specs in the __test/teacher-spec.js__ file to test that you 48 | have created the `Teacher` class correctly: 49 | 50 | ```shell 51 | npm test test/teacher-spec.js 52 | ``` -------------------------------------------------------------------------------- /week-4/d2-es6-classes/practices/01-common-js-modules/README.md: -------------------------------------------------------------------------------- 1 | # Practice: Import and Export with Common JS Modules 2 | 3 | In this exercise, you will practice importing and exporting using common JS. 4 | 5 | ## Set up 6 | 7 | Clone the starter from the **Download** link at the bottom of this page. 8 | 9 | ## Directions 10 | 11 | 1. Export `helloMessage` from __messages/hello-message.js__ and import it into 12 | __messages/say-message.js__. If you run the __messages/say-message.js__ file, 13 | you should see the following printed in the terminal: 14 | 15 | ```plaintext 16 | "Greetings! Let us begin!" 17 | ``` 18 | 19 | 2. Export `sayMessage` from __messages/say-message.js__ and import it into 20 | __send-messages/say-hello-to.js__. If you run the 21 | __send-messages/say-hello-to.js__ file, you should see the following printed 22 | in the terminal: 23 | 24 | ```plaintext 25 | "Greetings! Let us begin!" 26 | "Hello Woody!" 27 | ``` 28 | 29 | 3. Export `sayHelloTo` from __send-messages/say-hello-to.js__ and import it into 30 | __send-messages/give-message-to-mrs-potato.js__. If you run the 31 | __send-messages/give-message-to-mrs-potato.js__ file, you should see the 32 | following printed in the terminal: 33 | 34 | ```plaintext 35 | "Greetings! Let us begin!" 36 | "Hello Woody!" 37 | "Hello Mrs. Potato!" 38 | (Psst... Hi Buzz) 39 | ``` 40 | 41 | 4. Run the __index.js__ file. You should see an error in the terminal. Import or 42 | export from files until there are no more errors in the terminal. Once you 43 | successfully exported the necessary modules for the __index.js__ file and 44 | imported them, you should see the following printed in the terminal: 45 | 46 | ```plaintext 47 | "Greetings! Let us begin!" 48 | "Hello Woody!" 49 | "Hello Mrs. Potato!" 50 | (Psst... Hi Buzz) 51 | "Hello Mr. Potato!" 52 | "Hello Mrs. Potato!" 53 | (Psst... You are looking very spudly today!) 54 | "Hello Mrs. Potato!" 55 | (Psst... There's a good deal on mattresses tomorrow.) 56 | "Hello Mrs. Potato!" 57 | (Psst... Do you like to do things in unnecessarily complicated ways?) 58 | ``` 59 | -------------------------------------------------------------------------------- /week-5/d2-binary-hexa-ascii-memory-arrays/practices/03-dynamic-arrays/test/dynamic-array-practice-specs.js: -------------------------------------------------------------------------------- 1 | 2 | const { expect } = require('chai'); 3 | 4 | const DynamicArray = require('../dynamic-array.js'); 5 | 6 | const assert = require('assert') 7 | 8 | describe('Dynamic array', () => { 9 | 10 | let dynamicArr; 11 | 12 | beforeEach(function () { 13 | 14 | dynamicArr = new DynamicArray(8); 15 | 16 | }); 17 | 18 | it('has data, capacity and length properties', () => { 19 | 20 | expect(dynamicArr.length).to.equal(0); 21 | expect(dynamicArr.capacity).to.equal(8); 22 | expect(dynamicArr.data instanceof Array).to.be.true; 23 | expect(dynamicArr.data.length).to.deep.equal(8); 24 | 25 | }); 26 | 27 | 28 | it('can be initialized to different size', function () { 29 | 30 | dynamicArr = new DynamicArray(4); 31 | 32 | expect(dynamicArr.length).to.equal(0); 33 | expect(dynamicArr.capacity).to.equal(4); 34 | expect(dynamicArr.data.length).to.deep.equal(4); 35 | }); 36 | 37 | 38 | it('can read values in the array', function () { 39 | 40 | dynamicArr.data[0] = 99; 41 | dynamicArr.length = 1; 42 | 43 | expect(dynamicArr.read(0)).to.equal(99); 44 | expect(dynamicArr.read(1)).to.equal(undefined); 45 | }); 46 | 47 | 48 | 49 | it('can add values to the front using unshift', function () { 50 | 51 | expect(dynamicArr.length).to.equal(0); 52 | expect(dynamicArr.capacity).to.equal(8); 53 | 54 | dynamicArr.unshift(1); 55 | 56 | expect(dynamicArr.length).to.equal(1); 57 | expect(dynamicArr.capacity).to.equal(8); 58 | expect(dynamicArr.data[0]).to.deep.equal(1); 59 | 60 | dynamicArr.unshift(2); 61 | 62 | 63 | expect(dynamicArr.length).to.equal(2); 64 | expect(dynamicArr.capacity).to.equal(8); 65 | expect(dynamicArr.data[0]).to.deep.equal(2); 66 | expect(dynamicArr.data[1]).to.deep.equal(1); 67 | 68 | dynamicArr.unshift(3); 69 | 70 | expect(dynamicArr.length).to.equal(3); 71 | expect(dynamicArr.capacity).to.equal(8); 72 | expect(dynamicArr.data[0]).to.deep.equal(3); 73 | expect(dynamicArr.data[1]).to.deep.equal(2); 74 | expect(dynamicArr.data[2]).to.deep.equal(1); 75 | }); 76 | 77 | }); 78 | 79 | -------------------------------------------------------------------------------- /week-4/d3-context-bind-call-apply/practices/04-context-arrow-functions/README.md: -------------------------------------------------------------------------------- 1 | # Practice: Review of Arrow functions and Context with Arrow functions 2 | 3 | In this practice, you will review the difference between a regular function and 4 | an arrow function. Then explore arrow functions and their unique ability to 5 | retain the context of where it was defined. 6 | 7 | ## Set up 8 | 9 | Clone the starter from the **Download** link at the bottom of this page. 10 | 11 | ## Instructions 12 | 13 | ## Phase 1: Review of Arrow functions 14 | 15 | Convert all the functions in the __review.js__ file into arrow functions. 16 | 17 | ## Phase 2: Context with Arrow functions 18 | 19 | You will be debugging a context bug by using a fat arrow function in the class 20 | definition. 21 | 22 | Take a look at the code in the __index.js__ file. 23 | 24 | The code instantiates a new `User` which is imported from the 25 | __classes/user.js__ file. An instance of a `User` has a property of `name` and 26 | a method of `changeName(newName)` that will set the `name` property to the 27 | `newName` passed in as an argument. 28 | 29 | Back in the __index.js__ file, a function called 30 | `greetAfterNameChange(changeName, newName)` is defined. This function accepts 31 | a `changeName` function and invokes it with the `newName` passed in. The return 32 | value of the `changeName` function is saved to a variable called `name` and is 33 | printed to the console like so: `Hi my name is ${name}`. 34 | 35 | If you run the __index.js__ file with `node index.js`, the following should be 36 | printed to the terminal: 37 | 38 | ```plaintext 39 | Hi my name is Elle 40 | ``` 41 | 42 | However, there is a problem with the code. When invoking 43 | `greeAfterNamechange(changeName, newName)` with the `changeName` instance method 44 | on the newly instantiated user, the context of the `changeName` function is lost 45 | so there will be an error thrown when running the __index.js__ file. 46 | 47 | Use your debugging skills to change the code to use an arrow function to solve 48 | this context problem. 49 | 50 |
Hint: Use an arrow function somewhere in the 51 | User class definition to make sure that the changeName 52 | instance method retains its context.
-------------------------------------------------------------------------------- /week-4/d2-es6-classes/notes/wallet.js: -------------------------------------------------------------------------------- 1 | class Wallet { 2 | constructor(startAmount, cards=[]) { 3 | this.balance = startAmount; 4 | this.cards = cards; 5 | this.color = red; 6 | } 7 | 8 | addMoney(amount) { 9 | this.balance += amount; 10 | } 11 | 12 | removeMoney(amount) { 13 | this.balance -= amount; 14 | } 15 | 16 | getBalance() { 17 | return this.balance; 18 | } 19 | 20 | getCardCount() { 21 | return this.cards.length; 22 | } 23 | 24 | putCardIn(card) { 25 | this.cards.push(card); 26 | } 27 | 28 | getCardOut(name) { 29 | const index = this.cards.findIndex(x => x.name === name); 30 | if (index === -1) return null; 31 | const card = this.cards[index]; 32 | this.cards.splice(index, 1); 33 | return card; 34 | } 35 | } 36 | 37 | 38 | 39 | console.log('Create a wallet with $101 in it.'); 40 | const wallet = new Wallet(101); 41 | 42 | console.log('Balance:', wallet.getBalance()); 43 | console.log('my cards', wallet.cards) 44 | // console.log(); 45 | // console.log('Add $32'); 46 | // wallet.addMoney(32); 47 | // console.log('Balance:', wallet.getBalance()); 48 | // console.log(); 49 | // console.log('Spend $98'); 50 | // wallet.removeMoney(98); 51 | // console.log('Balance:', wallet.getBalance()); 52 | // console.log(); 53 | console.log('Put an AMEX in the wallet'); 54 | 55 | const card = { 56 | name: 'AMEX', 57 | number: '3524 100098 11223' 58 | }; 59 | 60 | wallet.putCardIn(card); 61 | console.log("my cards", wallet.cards); 62 | 63 | // console.log('Card count:', wallet.getCardCount()); 64 | // console.log(); 65 | // console.log('Get Visa:', wallet.getCardOut('Visa')); 66 | // console.log('Card count:', wallet.getCardCount()); 67 | // console.log(); 68 | // console.log('Get AMEX:', wallet.getCardOut('AMEX')); 69 | // console.log('Card count:', wallet.getCardCount()); 70 | // console.log(); 71 | 72 | // const curtisWallet = new Wallet(100, []); 73 | // const bartsWallet = new Wallet(324, [{ 74 | // name: 'Visa', 75 | // number: '0000 0000 0000 0000', 76 | // }]); 77 | 78 | 79 | // curtisWallet.addMoney(15); 80 | // bartsWallet.addMoney(16); 81 | 82 | // console.log(curtisWallet.getBalance()); 83 | // console.log(bartsWallet.getBalance()); 84 | // console.log(curtisWallet.getCardCount()); 85 | // console.log(bartsWallet.getCardCount()); -------------------------------------------------------------------------------- /week-5/d2-binary-hexa-ascii-memory-arrays/practices/02-ascii-advanced-conversion-functions/ascii-advanced-conversion-functions.js: -------------------------------------------------------------------------------- 1 | /* 2 | Implement these functions to convert values into the appropriate number base. 3 | Consult documentation on how to utilize the following methods: 4 | parseInt() 5 | toString() 6 | String.fromCharCode() 7 | charCodeAt() 8 | */ 9 | 10 | /* Base 2 to base 16 */ 11 | function binaryToHexadecimal(blob) { 12 | // Your code here 13 | } 14 | 15 | /* Base 16 to base 2 */ 16 | function hexadecimalToBinary(blob) { 17 | // Your code here 18 | } 19 | 20 | /* Base 10 to ASCII */ 21 | function decimalToAscii(blob) { 22 | // Your code here 23 | } 24 | 25 | /* Base 2 to ASCII */ 26 | function binaryToAscii(blob) { 27 | // Your code here 28 | } 29 | 30 | /* Base 16 to ASCII */ 31 | function hexadecimalToAscii(blob) { 32 | // Your code here 33 | } 34 | 35 | /* ASCII to base 10 */ 36 | function asciiToDecimal(blob) { 37 | // Your code here 38 | } 39 | 40 | // console.log('Binary to hexadecimal:') 41 | // console.log(binaryToHexadecimal('0b1010')) // '0xa' 42 | // console.log(binaryToHexadecimal('0b0011')) // '0x3' 43 | // console.log('') 44 | 45 | // console.log('Hexadecimal to binary:') 46 | // console.log(hexadecimalToBinary('0xa1')) // '0b10100001' 47 | // console.log(hexadecimalToBinary('0xff')) // '0b11111111' 48 | // console.log('') 49 | 50 | // console.log('Decimal to ASCII:') 51 | // console.log(decimalToAscii(65)) // 'A' 52 | // console.log(decimalToAscii(97)) // 'a' 53 | // console.log('') 54 | 55 | // console.log('Binary to ASCII:') 56 | // console.log(binaryToAscii('0b01000010')) // 'B' 57 | // console.log(binaryToAscii('0b01100010')) // 'b' 58 | // console.log('') 59 | 60 | // console.log('Hexadecimal to ASCII:') 61 | // console.log(hexadecimalToAscii('0x43')) // 'C' 62 | // console.log(hexadecimalToAscii('0x63')) // 'c' 63 | // console.log('') 64 | 65 | // console.log('ASCII to decimal:') 66 | // console.log(asciiToDecimal('HELLO')) // [ 72, 69, 76, 76, 79 ] 67 | // console.log(asciiToDecimal('world!')) // [ 119, 111, 114, 108, 100, 33 ] 68 | 69 | module.exports = { 70 | binaryToHexadecimal, 71 | hexadecimalToBinary, 72 | decimalToAscii, 73 | binaryToAscii, 74 | hexadecimalToAscii, 75 | asciiToDecimal 76 | } 77 | -------------------------------------------------------------------------------- /week-6/d1-sorting-bubble-insertion-selection/practices/02-insertion-sort/test/sort-specs.js: -------------------------------------------------------------------------------- 1 | const { expect } = require('chai'); 2 | 3 | const chai = require('chai'); 4 | const spies = require('chai-spies'); 5 | 6 | chai.use(spies); 7 | 8 | const [insertionSort, insertionSortInPlace] = require("../insertion-sort.js"); 9 | 10 | describe ('Basic Sorting Algorithms', function () { 11 | 12 | let arr; 13 | let consoleSpy; 14 | 15 | beforeEach(function () { 16 | 17 | consoleSpy = chai.spy.on(console, 'log'); 18 | 19 | arr = [2,4,6,8,1,3,5,7,9]; 20 | }); 21 | 22 | afterEach(() => { 23 | chai.spy.restore(console, 'log'); 24 | }); 25 | 26 | it('performs a out-of-place insertion sort', function () { 27 | 28 | let newArr = insertionSort(arr); 29 | 30 | expect(consoleSpy).on.nth(1).be.called.with(''); 31 | expect(consoleSpy).on.nth(2).be.called.with('9'); 32 | expect(consoleSpy).on.nth(3).be.called.with('7,9'); 33 | expect(consoleSpy).on.nth(4).be.called.with('5,7,9'); 34 | expect(consoleSpy).on.nth(5).be.called.with('3,5,7,9'); 35 | expect(consoleSpy).on.nth(6).be.called.with('1,3,5,7,9'); 36 | expect(consoleSpy).on.nth(7).be.called.with('1,3,5,7,8,9'); 37 | expect(consoleSpy).on.nth(8).be.called.with('1,3,5,6,7,8,9'); 38 | expect(consoleSpy).on.nth(9).be.called.with('1,3,4,5,6,7,8,9'); 39 | 40 | expect(newArr).to.deep.equal([1,2,3,4,5,6,7,8,9]); 41 | expect(arr).to.deep.equal([2,4,6,8,1,3,5,7,9]); 42 | 43 | }); 44 | 45 | it('performs an in-place insertion sort', function () { 46 | 47 | insertionSortInPlace(arr); 48 | 49 | expect(consoleSpy).on.nth(1).be.called.with('2,4,6,8,1,3,5,7,9'); 50 | expect(consoleSpy).on.nth(2).be.called.with('2,4,6,8,1,3,5,7,9'); 51 | expect(consoleSpy).on.nth(3).be.called.with('2,4,6,8,1,3,5,7,9'); 52 | expect(consoleSpy).on.nth(4).be.called.with('2,4,6,8,1,3,5,7,9'); 53 | expect(consoleSpy).on.nth(5).be.called.with('1,2,4,6,8,3,5,7,9'); 54 | expect(consoleSpy).on.nth(6).be.called.with('1,2,3,4,6,8,5,7,9'); 55 | expect(consoleSpy).on.nth(7).be.called.with('1,2,3,4,5,6,8,7,9'); 56 | expect(consoleSpy).on.nth(8).be.called.with('1,2,3,4,5,6,7,8,9'); 57 | 58 | expect(arr).to.deep.equal([1,2,3,4,5,6,7,8,9]); 59 | 60 | }); 61 | 62 | }); 63 | 64 | -------------------------------------------------------------------------------- /week-6/d2-binary-search-merge-quicksort/notes/array-sort-method.js: -------------------------------------------------------------------------------- 1 | /* 2 | Array.sort() 3 | */ 4 | 5 | const numbers = [5, 6, 4, 3, 2, 0, 1]; 6 | const letters = ['C', 'B', 'F', 'A', 'D', 'G', 'E']; 7 | const lettersMix = ['c', 'B', 'F', 'A', 'd', 'g', 'E']; 8 | 9 | // console.log(numbers.sort()); // [ 0, 1, 2, 3, 4, 5, 6 ] 10 | // console.log(letters.sort()); // [ 'A', 'B', 'C', 'D', 'E', 'F', 'G' ] 11 | console.log(lettersMix.sort()); // 12 | 13 | const moreNumbers = [10, 120, 100, 1100, 11]; 14 | 15 | // console.log('default sort: ', moreNumbers.sort()); // ??? 16 | 17 | // moreNumbers.sort((a, b) => console.log({ a }, { b })); 18 | 19 | function wat(array) { 20 | for (let i = 0; i < array.length; i++) { 21 | const ele = `${array[i]}` 22 | console.log('ele:', ele) 23 | 24 | for (let j = 0; j < ele.length; j++) { 25 | console.log(`UTF-16 code at ele index ${j}: ${ele.charCodeAt(j)}`); 26 | } 27 | } 28 | } 29 | 30 | // wat(moreNumbers) 31 | // wat(letters) 32 | // wat(numbers) 33 | 34 | /* 35 | compareFunction(a, b) return value sort order 36 | > 0 sort b before a 37 | < 0 sort a before b 38 | */ 39 | 40 | // // ascending 41 | // console.log('ascending sort: ', moreNumbers.sort((a, b) => a - b)); // a = 1000 - b = 10 === positive 42 | 43 | // // descending 44 | // console.log('descending sort: ', moreNumbers.sort((a, b) => b - a)); // b = 1000 - a = 10 === negative 45 | 46 | 47 | const petData = [ 48 | {'name': 'Salsa', 'age':10, 'animal': 'cat', 'description': 'calico' }, 49 | {'name': 'Jazz', 'age':7, 'animal': 'cat', 'description': 'tuxedo' }, 50 | {'name': 'Mars', 'age':6, 'animal': 'dog', 'description': 'shepard' }, 51 | {'name': 'Blondie', 'age':12, 'animal': 'dog', 'description': 'labrador' }, 52 | {'name': 'Blues', 'age':5, 'animal': 'cat', 'description': 'tabby' }, 53 | {'name': 'Venus', 'age':3, 'animal': 'dog', 'description': 'husky' }, 54 | ] 55 | 56 | // console.log('Not sorted: ', petData) 57 | 58 | function sortPets() { 59 | return petData.sort((a, b) => { 60 | if (a.animal === b.animal) return a.age - b.age 61 | else if (a.animal === 'cat') return 1 62 | else if (a.animal === 'dog') return -1 63 | }) 64 | } 65 | 66 | 67 | // console.log('Sorted: ', sortPets()) 68 | -------------------------------------------------------------------------------- /week-4/d3-context-bind-call-apply/practices/02-bind/README.md: -------------------------------------------------------------------------------- 1 | # Practice: Bind 2 | 3 | In this practice, you will practice identifying when to use `bind` and how to 4 | use it. 5 | 6 | ## Set up 7 | 8 | Clone the starter from the **Download** link at the bottom of this page. 9 | 10 | ## Instructions 11 | 12 | Implement the following in the __employee.js__ file. 13 | 14 | 1. Create a class called `Employee`. 15 | 16 | 2. The constructor method should take in a `name` and `occupation` for the 17 | `Employee` and initialize them as instance variables. 18 | 19 | 3. Add an instance method called `sayName()` that will `console.log` the 20 | `Employee`'s name like so: `${name} says hello`. 21 | 22 | 4. Add another instance method called `sayOccupation()` that will `console.log` 23 | the `Employee`'s name and occupation like so: `${name} is a ${occupation}`. 24 | 25 | 5. Export the `Employee` class from the file. 26 | 27 | To test your code, implement the following in the __test.js__ file. 28 | 29 | 1. Import the `Employee` class. 30 | 31 | 2. Create a new `Employee` with the `name` of "John Wick" and an `occupation` of 32 | "Dog Lover". 33 | 34 | 3. Call the `sayName()` instance method on the new `Employee` in a `setTimeout` 35 | after 2 seconds. Question: What do you expect to be printed to the terminal 36 | and why? 37 |
Answer: "undefined says hello" will be printed 38 | to the terminal because the `sayName()` instance method on the new `Employee` 39 | was invoked function-style by the `setTimeout` after 2 seconds.
40 | Solve the problem using `bind` to make sure that "John Wick says hello" will 41 | be printed to the terminal after 2 seconds. 42 | 43 | 3. Call the `sayOccupation()` instance method on the new `Employee` in a 44 | `setTimeout` after 3 seconds. Question: What do you expect to be printed to 45 | the terminal and why? 46 |
Answer: "undefined is a undefined" will be printed 47 | to the terminal because the `sayOccupation()` instance method on the new 48 | `Employee` was invoked function-style by the `setTimeout` after 3 49 | seconds.
50 | Solve the problem using `bind` to make sure that "John Wick is a Dog Lover" 51 | will be printed to the terminal after 3 seconds. -------------------------------------------------------------------------------- /week-5/d4-hash-tables-and-sets/notes/tabulation.js: -------------------------------------------------------------------------------- 1 | /* 2 | Tabulation is another way to optimize slower functions. 3 | Two main features of tabulation: 4 | 1. the function is iterative and NOT recursive 5 | 2. the additional data structure is typically an array, 6 | commonly referred to as the table. 7 | 8 | Many problems that can be solved with memoization can also be solved 9 | with tabulation, as long as you convert from recursion to iteration. 10 | 11 | Consider this implementation of fibonacci: 12 | */ 13 | 14 | function tabulatedFib(n) { 15 | // create a blank array with n reserved spots 16 | let table = new Array(n); 17 | if (table[n]) return table[n] 18 | // seed the first two values 19 | table[0] = 0; 20 | table[1] = 1; 21 | 22 | // complete the table by moving from left to right, 23 | // following the fibonacci pattern 24 | for (let i = 2; i <= n; i += 1) { 25 | table[i] = table[i - 1] + table[i - 2]; 26 | } 27 | 28 | return table[n]; 29 | } 30 | 31 | console.log(tabulatedFib(7)); // => 13 32 | 33 | /* 34 | The space and time complexities in this implementation would be O(n) as the 35 | length of the array would be n elements long. 36 | 37 | We can refactor for O(1) space by setting up an array to only hold the two most 38 | recent calculations, as that is all that is needed to find the next fibonacci 39 | number. 40 | */ 41 | 42 | function fib(n) { 43 | let mostRecentCalcs = [0, 1]; 44 | 45 | if (n === 0) return mostRecentCalcs[0]; 46 | 47 | for (let i = 2; i <= n; i++) { 48 | const [secondLast, last] = mostRecentCalcs; 49 | mostRecentCalcs = [last, secondLast + last]; 50 | } 51 | 52 | return mostRecentCalcs[1]; 53 | } 54 | 55 | /* 56 | The formula for creating a tabulated formula is as follows: 57 | 1. Create the table array based off of the size of the input, which isn't always 58 | straightforward if you have multiple input values 59 | 60 | 2. Initialize some values in the table that "answer" the trivially small 61 | subproblem usually by initializing the first entry (or entries) of the table 62 | 63 | 3. Iterate through the array and fill in remaining entries, using previous 64 | entries in the table to perform the current calculation 65 | 66 | 4. Your final answer is (usually) the last entry in the table 67 | 68 | */ -------------------------------------------------------------------------------- /week-5/d2-binary-hexa-ascii-memory-arrays/notes/stacks.js: -------------------------------------------------------------------------------- 1 | /* 2 | Stacks represent a linear collection of nodes or values. 3 | 4 | 5 | Stacks: LIFO(Last In, First Out) data structures. 6 | -the last Node added is always the first Node to be removed 7 | -the first Node added is always the last Node to be removed 8 | 9 | **It is helpful to visualize a stack as a vertical stack of items. 10 | -we add to the top of the stack. We remove from the top of the stack. 11 | 12 | 13 | Stacks and Queues are so similar that we can look at both of their properties together: 14 | 15 | Stack Property Description 16 | top The first node in the Stack 17 | ---- Stacks do not have an equivalent 18 | 19 | length The number of nodes in the Stack; 20 | the Stack's length. 21 | 22 | 23 | 24 | Each node in the stack has these properties: 25 | 26 | Property Description 27 | value The actual value this node represents. 28 | next The next node in the Stack (relative to this node). 29 | 30 | 31 | Stack Methods: 32 | Type Name Description Returns 33 | Insertion push Adds a Node to the top of the Stack. Integer - New size of stack 34 | Deletion pop Removes a Node from the top of the Stack. Node removed from top of Stack 35 | Meta size Returns the current size of the Stack. Integer 36 | 37 | 38 | 39 | */ 40 | 41 | // class _Node { 42 | // constructor(value) { 43 | // this.value = value; 44 | // this.next = null; 45 | // } 46 | // } 47 | 48 | //We will be implementing stacks as arrays 49 | 50 | class Stack { 51 | constructor() { 52 | this.store = new Array(); 53 | } 54 | size() { 55 | //return the length of the stack 56 | return this.store.length; 57 | } 58 | 59 | push(ele) { 60 | //this will add element to end of stack 61 | this.store.push(ele); 62 | return true; 63 | } 64 | 65 | pop() { 66 | //remove the last element 67 | return this.store.pop(); 68 | } 69 | 70 | peek() { 71 | //return the last element 72 | return this.store[this.store.length - 1]; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /week-6/d1-sorting-bubble-insertion-selection/practices/03-selection-sort/test/sort-specs.js: -------------------------------------------------------------------------------- 1 | const { expect } = require('chai'); 2 | 3 | const chai = require('chai'); 4 | const spies = require('chai-spies'); 5 | 6 | chai.use(spies); 7 | 8 | const [selectionSort, selectionSortInPlace] = require("../selection-sort.js"); 9 | 10 | describe ('Basic Sorting Algorithms', function () { 11 | 12 | let arr; 13 | let consoleSpy; 14 | 15 | beforeEach(function () { 16 | 17 | consoleSpy = chai.spy.on(console, 'log'); 18 | 19 | arr = [2,4,6,8,1,3,5,7,9]; 20 | }); 21 | 22 | afterEach(() => { 23 | chai.spy.restore(console, 'log'); 24 | }); 25 | 26 | 27 | it('performs a out-of-place selection sort', function () { 28 | 29 | let newArr = selectionSort(arr); 30 | 31 | expect(consoleSpy).on.nth(1).be.called.with(''); 32 | expect(consoleSpy).on.nth(2).be.called.with('1'); 33 | expect(consoleSpy).on.nth(3).be.called.with('1,2'); 34 | expect(consoleSpy).on.nth(4).be.called.with('1,2,3'); 35 | expect(consoleSpy).on.nth(5).be.called.with('1,2,3,4'); 36 | expect(consoleSpy).on.nth(6).be.called.with('1,2,3,4,5'); 37 | expect(consoleSpy).on.nth(7).be.called.with('1,2,3,4,5,6'); 38 | expect(consoleSpy).on.nth(8).be.called.with('1,2,3,4,5,6,7'); 39 | expect(consoleSpy).on.nth(9).be.called.with('1,2,3,4,5,6,7,8'); 40 | 41 | expect(newArr).to.deep.equal([1,2,3,4,5,6,7,8,9]); 42 | expect(arr).to.deep.equal([2,4,6,8,1,3,5,7,9]); 43 | 44 | }); 45 | 46 | it('performs an in-place selection sort', function () { 47 | 48 | selectionSortInPlace(arr); 49 | 50 | expect(consoleSpy).on.nth(1).be.called.with('2,4,6,8,1,3,5,7,9'); 51 | expect(consoleSpy).on.nth(2).be.called.with('1,2,4,6,8,3,5,7,9'); 52 | expect(consoleSpy).on.nth(3).be.called.with('1,2,4,6,8,3,5,7,9'); 53 | expect(consoleSpy).on.nth(4).be.called.with('1,2,3,4,6,8,5,7,9'); 54 | expect(consoleSpy).on.nth(5).be.called.with('1,2,3,4,6,8,5,7,9'); 55 | expect(consoleSpy).on.nth(6).be.called.with('1,2,3,4,5,6,8,7,9'); 56 | expect(consoleSpy).on.nth(7).be.called.with('1,2,3,4,5,6,8,7,9'); 57 | expect(consoleSpy).on.nth(8).be.called.with('1,2,3,4,5,6,7,8,9'); 58 | expect(consoleSpy).on.nth(9).be.called.with('1,2,3,4,5,6,7,8,9'); 59 | 60 | expect(arr).to.deep.equal([1,2,3,4,5,6,7,8,9]); 61 | 62 | }); 63 | 64 | 65 | }); 66 | 67 | -------------------------------------------------------------------------------- /week-5/d1-big-o-arrays/extra-practice/big-o-intro-extra-practice/solutions/02-anagram.js: -------------------------------------------------------------------------------- 1 | // O(n^2) quadratic time 2 | // O(n) linear space 3 | function firstAnagram(str1, str2) { 4 | let arr1 = str1.split(""), 5 | arr2 = str2.split(""); 6 | 7 | for (let letter of arr1) { 8 | let index = arr2.indexOf(letter); 9 | if (index === -1) return false; 10 | arr2.splice(index, 1); 11 | } 12 | 13 | return !arr2.length; 14 | } 15 | 16 | // O(n*log(n)) linearithmic time 17 | // O(n) linear space 18 | function secondAnagram(str1, str2) { 19 | str1.split("").sort().join(""); 20 | str2.split("").sort().join(""); 21 | 22 | return str1 === str2; 23 | } 24 | 25 | // O(n) linear time 26 | // O(1) constant space 27 | // Here, the intuitive answer to the space complexity is 28 | // O(n) because we're adding a separate key in the object 29 | // for each character. But if the keys in the object are single 30 | // characters, then how many different keys can we have? 31 | // How many different chars in the alphabet? A constant number 32 | // (26 + numbers and symbols for English alphabet). 33 | function thirdAnagram(str1, str2) { 34 | let letterCounts1 = {}, 35 | letterCounts2 = {}; 36 | 37 | str1 38 | .split("") 39 | .forEach((e) => (letterCounts1[e] = (letterCounts1[e] || 0) + 1)); 40 | str2 41 | .split("") 42 | .forEach((e) => (letterCounts2[e] = (letterCounts2[e] || 0) + 1)); 43 | 44 | const haveSameCount = function (obj1, obj2) { 45 | const obj1Length = Object.keys(obj1).length; 46 | const obj2Length = Object.keys(obj2).length; 47 | 48 | if (obj1Length === obj2Length) { 49 | return Object.keys(obj1).every( 50 | (key) => obj2.hasOwnProperty(key) && obj2[key] === obj1[key] 51 | ); 52 | } 53 | return false; 54 | }; 55 | return haveSameCount(letterCounts1, letterCounts2); 56 | } 57 | 58 | // O(n) linear time 59 | // O(1) constant space (same logic as above) 60 | function bonusAnagram(str1, str2) { 61 | let letterSums = {}; 62 | 63 | // If we do the exact same subractions for each letter in 64 | // str2 as we do additions for str1, letter_sums will all be 0. 65 | str1.split("").forEach((e) => (letterSums[e] = (letterSums[e] || 0) + 1)); 66 | str2.split("").forEach((e) => (letterSums[e] = (letterSums[e] || 0) - 1)); 67 | 68 | // It's a zero-sum game! 69 | return Object.values(letterSums).every((sum) => sum === 0); 70 | } 71 | -------------------------------------------------------------------------------- /week-4/d2-es6-classes/practices/02-basic-class-syntax/test/person-spec.js: -------------------------------------------------------------------------------- 1 | const chai = require("chai"); 2 | const spies = require("chai-spies"); 3 | chai.use(spies); 4 | const expect = chai.expect; 5 | 6 | const Person = require("../classes/person"); 7 | 8 | describe("Person class", () => { 9 | let person; 10 | let consoleSpy 11 | beforeEach(() => { 12 | person = new Person("kristen", "chauncey", 38); 13 | consoleSpy = chai.spy.on(console, 'log'); 14 | }); 15 | 16 | afterEach(() => { 17 | chai.spy.restore(console); 18 | }); 19 | 20 | describe("Person constructor", () => { 21 | it("should set the firstName property", () => { 22 | expect(person).to.have.property("firstName"); 23 | expect(person.firstName).to.eql("kristen"); 24 | }); 25 | 26 | it("should set the lastName property", () => { 27 | expect(person).to.have.property("lastName"); 28 | expect(person.lastName).to.eql("chauncey"); 29 | }); 30 | 31 | it("should set the age property", () => { 32 | expect(person).to.have.property("age"); 33 | expect(person.age).to.eql(38); 34 | }); 35 | }); 36 | 37 | describe("introduce instance method", () => { 38 | it("should call the introduce method", () => { 39 | person.introduce(); 40 | let expected = `Hi, I'm kristen chauncey, and I'm 38 years old.`; 41 | expect(consoleSpy).to.have.been.called.once.with(expected) 42 | }); 43 | }); 44 | 45 | describe("introducePeople static method", () => { 46 | it("should call the introduce method on each instance", () => { 47 | const person2 = new Person("jeff", "granoff", 30); 48 | let introSpy = chai.spy.on(person, "introduce"); 49 | let introSpy2 = chai.spy.on(person2, "introduce"); 50 | Person.introducePeople([person, person2]); 51 | expect(introSpy).to.have.been.called.once; 52 | expect(introSpy2).to.have.been.called.once; 53 | }); 54 | 55 | it("should throw an error if input is not an array", () => { 56 | let input = "bad input"; 57 | Person.introducePeople(input); 58 | expect(consoleSpy).to.have.been.called.once.with( 59 | "introducePeople only takes an array as an argument." 60 | ); 61 | }); 62 | 63 | it('should throw an error if array does not contain instances of Person', () => { 64 | let input = ['dog', person] 65 | Person.introducePeople(input); 66 | expect(consoleSpy).to.have.been.called.once.with( 67 | "All items in array must be Person class instances." 68 | ); 69 | }) 70 | }); 71 | }); 72 | -------------------------------------------------------------------------------- /week-5/d1-big-o-arrays/practices/01-timing-benchmarks/test/phase-1-spec.js: -------------------------------------------------------------------------------- 1 | const { expect } = require('chai'); 2 | 3 | const [addNums, addManyNums] = require("../phase-1.js"); 4 | 5 | describe ('addNums', function () { 6 | 7 | it('adds all integers 1-10', function () { 8 | 9 | // 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = 55 10 | expect(addNums(10)).to.equal(55); 11 | 12 | }); 13 | 14 | it('adds all integers 1-100', function () { 15 | 16 | expect(addNums(100)).to.equal(5050); 17 | 18 | }); 19 | 20 | 21 | it('adds all integers 1 to 1000', function () { 22 | 23 | expect(addNums(1000)).to.equal(500500); 24 | 25 | }); 26 | 27 | 28 | it('adds all integers 1 to 10000', function () { 29 | 30 | expect(addNums(10000)).to.equal(50005000); 31 | 32 | }); 33 | 34 | 35 | it('adds all integers 1 to 100000', function () { 36 | 37 | expect(addNums(10000)).to.equal(50005000); 38 | 39 | }); 40 | 41 | 42 | it('adds all integers 1 to 1000000', function () { 43 | 44 | expect(addNums(100000)).to.equal(5000050000); 45 | 46 | }); 47 | 48 | 49 | it('adds all integers 1 to 10000000', function () { 50 | 51 | startTime = Date.now(); 52 | expect(addNums(1000000)).to.equal(500000500000); 53 | endTime = Date.now(); 54 | 55 | }); 56 | 57 | 58 | it('runs in O(n) time', function () { 59 | 60 | // n = 10 million 61 | const startTime = Date.now(); 62 | addNums(10000000); 63 | const endTime = Date.now(); 64 | 65 | const runtime = endTime - startTime 66 | 67 | // Don't get too clever, should run in O(n) time 68 | expect(runtime).to.be.above(3); 69 | 70 | // Even slow computers should be able to run in under 800ms 71 | expect(runtime).to.be.below(800); 72 | 73 | }); 74 | 75 | }); 76 | 77 | describe ('addManyNums', function () { 78 | 79 | 80 | it('adds all values of addNums(1) through addNums(10)', function () { 81 | 82 | // addNums(1) + addNums(2) + addNums(3) + addNums(4) + addNums(5) + 83 | // addNums(6) + addNums(7) + addNums(8) + addNums(9) + addNums(10) = 220 84 | 85 | expect(addManyNums(10)).to.equal(220); 86 | 87 | }); 88 | 89 | it('adds all values of addNums(1) through addNums(100)', function () { 90 | 91 | 92 | expect(addManyNums(100)).to.equal(171700); 93 | 94 | }); 95 | 96 | 97 | it('adds all values of addNums(1) through addNums(1000)', function () { 98 | 99 | expect(addManyNums(1000)).to.equal(167167000); 100 | 101 | }); 102 | 103 | }); 104 | -------------------------------------------------------------------------------- /week-5/d3-linked-lists-and-queues/practices/01-linked-lists/test/linked-list-practice-specs.js: -------------------------------------------------------------------------------- 1 | const { expect } = require('chai'); 2 | 3 | const LinkedList = require('../linked-list.js') 4 | 5 | describe('Linked List', () => { 6 | describe('Linked List - Constructor', () => { 7 | let linkedList; 8 | 9 | beforeEach(function () { 10 | linkedList = new LinkedList(); 11 | }); 12 | 13 | it('has head property that is initialized to null', () => { 14 | expect(linkedList.head).to.equal(null); 15 | }); 16 | 17 | it('has length property that is initialized to 0', () => { 18 | expect(linkedList.length).to.equal(0); 19 | }); 20 | 21 | it('does not have a tail pointer', () => { 22 | expect(linkedList.tail).to.equal(undefined); 23 | }); 24 | }); 25 | 26 | 27 | describe('Linked List - addToHead', () => { 28 | let linkedList; 29 | 30 | beforeEach(function () { 31 | linkedList = new LinkedList(); 32 | 33 | linkedList.addToHead(1); 34 | linkedList.addToHead(2); 35 | linkedList.addToHead(3); 36 | }); 37 | 38 | it('addToHead adds the correct head node', () => { 39 | expect(linkedList.head.value).to.equal(3); 40 | }); 41 | 42 | it('addToHead links all of the nodes in the correct order', () => { 43 | expect(linkedList.head.next.value).to.equal(2); 44 | expect(linkedList.head.next.next.value).to.equal(1); 45 | }); 46 | 47 | it('addToHead correctly modifies the length property', () => { 48 | expect(linkedList.length).to.equal(3); 49 | }); 50 | }); 51 | 52 | 53 | describe('Linked List - addToTail', () => { 54 | let linkedList; 55 | 56 | beforeEach(function () { 57 | linkedList = new LinkedList(); 58 | 59 | linkedList.addToTail(1); 60 | linkedList.addToTail(2); 61 | linkedList.addToTail(3); 62 | }); 63 | 64 | it('addToTail adds the correct tail value', () => { 65 | expect(linkedList.head.next.next.value).to.equal(3); 66 | }); 67 | 68 | it('addToTail links all of the nodes in the correct order', () => { 69 | expect(linkedList.head.value).to.equal(1); 70 | expect(linkedList.head.next.value).to.equal(2); 71 | }); 72 | 73 | it('addToTail correctly modifies the length property', () => { 74 | expect(linkedList.length).to.equal(3); 75 | }); 76 | }); 77 | }); 78 | -------------------------------------------------------------------------------- /week-5/d1-big-o-arrays/extra-practice/big-o-intro-extra-practice/solutions/03-two-sum.js: -------------------------------------------------------------------------------- 1 | //O(n^2) quadratic time 2 | //O(1) constant space 3 | function badTwoSum(arr, targetSum) { 4 | for (let i = 0; i < arr.length - 1; i++) { 5 | for (let j = i + 1; j < arr.length; j++) { 6 | if (arr[i] + arr[j] === targetSum) return true; 7 | } 8 | } 9 | return false; 10 | } 11 | 12 | //O(nlogn) linearithmic time 13 | //O(n) linear space 14 | function okayTwoSum1(arr, targetSum) { 15 | arr.sort(); 16 | let i = 0, 17 | j = arr.length - 1; 18 | 19 | while (i < j) { 20 | let currentSum = arr[i] + arr[j]; 21 | if (currentSum > targetSum) { 22 | j -= 1; 23 | } else if (currentSum < targetSum) { 24 | i += 1; 25 | } else { 26 | return true; 27 | } 28 | } 29 | 30 | return false; 31 | } 32 | 33 | //O(nlogn) linearithmic time 34 | //O(n) linear space 35 | // another implementation using binary search 36 | function okayTwoSum2(arr, targetSum) { 37 | arr.sort(); 38 | for (let i = 0; i < arr.length; i++) { 39 | let num = arr[i]; 40 | let complement = targetSum - num; 41 | let complement_idx = binarySearch(arr, complement); 42 | if (complement_idx != -1 && complement_idx != i) { 43 | return true; 44 | } 45 | } 46 | 47 | return false; 48 | } 49 | 50 | function binarySearch(array, target) { 51 | let lowerIdx = 0, 52 | upperIdx = array.length - 1, 53 | midIdx; 54 | 55 | while (lowerIdx <= upperIdx) { 56 | midIdx = Math.floor((lowerIdx + upperIdx) / 2); 57 | if (array[midIdx] < target) { 58 | lowerIdx = midIdx + 1; 59 | } else if (array[midIdx] > target) { 60 | upperIdx = midIdx - 1; 61 | } else { 62 | return midIdx; 63 | } 64 | } 65 | 66 | return -1; 67 | } 68 | 69 | //O(n) linear time 70 | //O(n) linear space 71 | function twoSum(arr, targetSum) { 72 | let complements = {}; 73 | for (let num of arr) { 74 | let complement = targetSum - num; 75 | if (complements[complement]) return true; 76 | complements[num] = true; 77 | } 78 | 79 | return false; 80 | } 81 | 82 | //O(n) linear time 83 | //O(n) linear space 84 | // This can be easily adapted to also return the indices of the two numbers: 85 | function twoSumIndices(arr, targetSum) { 86 | let complements = {}; 87 | for (let i = 0; i < arr.length; i++) { 88 | let num = arr[i]; 89 | let complement = targetSum - num; 90 | if (complements[complement]) { 91 | let complement_idx = complements[complement]; 92 | return [i, complement_idx]; 93 | } 94 | complements[num] = i; 95 | } 96 | return []; 97 | } 98 | -------------------------------------------------------------------------------- /week-5/w5-review-guide/conversion-extra-practice/conversion-practice-solution.js: -------------------------------------------------------------------------------- 1 | //Convert the following: _HINT_: to be best prepared to do this on the test, create functions to do this. 2 | 3 | //Hexadecimal to decimal: 4 | function hexToDec(hexStr) { 5 | return parseInt(hexStr, 16); 6 | } 7 | console.log(hexToDec("309")); // => 777 8 | /**************************** */ 9 | 10 | //Decimal to Binary: 11 | //5687 12 | function decToBin(decimal) { 13 | return decimal.toString(2); 14 | } 15 | console.log(decToBin(5687)); // => 1011000110111 16 | /***************************** */ 17 | 18 | //Binary to Decimal: 19 | //0b101101 20 | function binToDec(binaryBlob) { 21 | return parseInt(binaryBlob, 2).toString(10); 22 | } 23 | console.log(binToDec(101101)); // => 45 24 | /****************************** */ 25 | 26 | //Decimal to Hexadecimal: 27 | //13453 28 | function decToHex(decimal) { 29 | return decimal.toString(16); 30 | } 31 | console.log(decToHex(13453)); // => 348d 32 | /****************************** */ 33 | 34 | //Hexadecimal to ASCII: 35 | function hexToASCII(hexStr) { 36 | let hex = hexStr.toString(); 37 | let str = ""; 38 | for (let n = 0; n < hex.length; n += 2) { 39 | str += String.fromCharCode(parseInt(hex.substr(n, 2), 16)); 40 | } 41 | return str; 42 | } 43 | console.log(hexToASCII("736F667477617265")); // => software 44 | /******************************* */ 45 | 46 | //Binary to ASCII: 47 | function binToASCII(binaryBlob) { 48 | let binString = ""; 49 | binaryBlob.split(" ").map((bin) => { 50 | binString += String.fromCharCode(parseInt(bin, 2)); 51 | }); 52 | return binString; 53 | } 54 | console.log( 55 | binToASCII( 56 | "01101010 01100001 01110110 01100001 01110011 01100011 01110010 01101001 01110000 01110100" 57 | ) 58 | ); // => javascript 59 | /******************************** */ 60 | 61 | //ASCII to Binary: 62 | //'appacademy' 63 | function ASCIIToBin(ASCIIStr) { 64 | let result = ""; 65 | for (let i = 0; i < ASCIIStr.length; i++) { 66 | let bin = ASCIIStr[i].charCodeAt().toString(2); 67 | result += Array(8 - bin.length + 1).join("0") + bin; 68 | } 69 | return result; 70 | } 71 | console.log(ASCIIToBin("appacademy")); // => 01100001011100000111000001100001011000110110000101100100011001010110110101111001 72 | /********************************* */ 73 | 74 | //ASCII to Hexadecimal: 75 | //'badger' 76 | function ASCIIToHex(ASCIIStr) { 77 | let arr = []; 78 | for (let i = 0, l = ASCIIStr.length; i < l; i++) { 79 | let hex = Number(ASCIIStr.charCodeAt(i)).toString(16); 80 | arr.push(hex); 81 | } 82 | return arr.join(""); 83 | } 84 | console.log(ASCIIToHex("badger")); // => 626164676572 85 | -------------------------------------------------------------------------------- /week-6/d3-binary-search-trees/practices/01-binary-search-trees/README-pt4.md: -------------------------------------------------------------------------------- 1 | # Practice: Binary Search Tree - Part 4 2 | 3 | In this exercise, you will be iteratively traversing a basic binary search tree. 4 | 5 | ## Setup 6 | 7 | 1. Continue working from the same starter as part 1, 2, and 3 8 | 2. Read the instructions and test specs to understand the problem 9 | 3. Fill out the code until tests are all green 10 | 11 | ## Part 4: Binary Search Tree iterative traversal 12 | 13 | Implement functions that will traverse the tree in depth and breadth first orders, 14 | printing the nodes out as it traverses. 15 | 16 | ```plaintext 17 | 4 18 | / \ 19 | 2 7 20 | / \ / \ 21 | 1 3 5 8 22 | ``` 23 | 24 | `depthFirstTraversal()` prints the node value first, then _iteratively_ visits 25 | the left and right nodes in depth-first order, going as deep as possible before 26 | backtracking at dead-ends to take the last path not taken. The example tree 27 | **could** print out `4, 2, 1, 3, 7, 5, 8`. This is one of several valid orders, 28 | but is what you will see if you always choose to go left before going right. 29 | 30 | You've seen this before in the reading, but implement it here without looking 31 | at that! The value isn't in possessing a working copy of the code, it's in 32 | understanding how it works and being able to create or modify it. 33 | 34 | ```javascript 35 | depthFirstTraversal() { 36 | // initialize a stack with the root node 37 | 38 | // while the stack is not empty 39 | // print and remove first node in stack 40 | 41 | // if the node has a left node 42 | // push the left node on the back of the stack 43 | // if the node has a right node 44 | // push the right node on the back of the stack 45 | } 46 | ``` 47 | 48 | `breadthFirstTraversal()` iteratively visits the nodes in breadth-first order, 49 | or layer by layer. The example tree **could** print out `4, 2, 7, 1, 3, 5, 8`. 50 | This is one of several valid orders, but is what you will see if you choose to 51 | always go left first before going right. 52 | 53 | Again, implement this here without looking at the reading! 54 | 55 | ```javascript 56 | breadthFirstTraversal() { 57 | // initialize a queue with the root node 58 | 59 | // while the queue is not empty 60 | // print and remove first node in queue 61 | 62 | // if the node has a left node 63 | // push the left node on the back of the queue 64 | // if the node has a right node 65 | // push the right node on the back of the queue 66 | } 67 | ``` 68 | 69 | Read through the specs in `test/binary-search-tree-spec.js` for more details. -------------------------------------------------------------------------------- /week-6/d3-binary-search-trees/practices/01-binary-search-trees/README.md: -------------------------------------------------------------------------------- 1 | # Binary Search Tree practice 2 | 3 | In this exercise, you will be implementing and traversing a basic binary 4 | search tree. 5 | 6 | ## Setup 7 | 8 | 1. Download the starter at the bottom of this page 9 | 2. Install all packages using `npm install` 10 | 3. Read the instructions and test specs to understand the problem 11 | 4. Fill out the code until tests are all green 12 | 13 | ## Part 1: Binary Search Tree construction 14 | 15 | Start by implementing the class constructor and `insert` function in 16 | `binary-search-tree.js`. 17 | 18 | `insert(val)` should insert new tree node with the given value into the 19 | correct location in the binary search tree. 20 | 21 | For example, inserting `4` into the empty tree will set the root node to 4. 22 | Inserting `3`, then `5` will insert two nodes to the left and right of the 23 | root respectively. The resulting tree will look like this: 24 | 25 | ```plaintext 26 | 4 27 | / \ 28 | 3 5 29 | ``` 30 | 31 | **hint** you may add default parameters to your functions to aid in recursion. 32 | For example, `insert(currentNode=this.root)` will default to inserting at the 33 | root, but allow you to pass in a child node to insert as well. 34 | 35 | Read through the specs in `test/binary-search-tree-spec.js` for more details. 36 | 37 | ## Part 2: Binary Search Tree search 38 | 39 | Now that you can build valid binary search trees, you can implement the 40 | `search` function. 41 | 42 | `search(val)` should return `true` if the value is in the tree and `false` if 43 | it is not. 44 | 45 | ```plaintext 46 | 4 47 | / \ 48 | 3 5 49 | ``` 50 | 51 | For example, in the tree pictured above, `bst.search(3)` would return `true` 52 | and `bst.search(6)` would return false. 53 | 54 | Read through the specs in `test/binary-search-tree-spec.js` for more details. 55 | 56 | 57 | ## Part 3: Binary Search Tree traversal 58 | 59 | Implement functions that will print out the tree nodes with a pre-order, 60 | in-order and post-order traversal. 61 | 62 | ```plaintext 63 | 4 64 | / \ 65 | 3 5 66 | ``` 67 | 68 | `preOrderTraversal()` prints the node value first, then recursively visits the 69 | left and right nodes. The example tree would print out `4, 3, 5`. 70 | 71 | `inOrderTraversal()` recursively visits the left node, then prints the current 72 | node value, then recursively visits the right node. The example tree would 73 | print out `3, 4, 5`. 74 | 75 | `postOrderTraversal()` recursively visits the left and right nodes, then 76 | prints the current node value. The example tree would print out `3, 5, 4`. 77 | 78 | Read through the specs in `test/binary-search-tree-spec.js` for more details. 79 | 80 | 81 | [starter]: https://github.com/appacademy-starters/practice-for-week-06-binary-search-tree-guided-practice -------------------------------------------------------------------------------- /week-5/d2-binary-hexa-ascii-memory-arrays/practices/02-ascii-advanced-conversion-functions/README.md: -------------------------------------------------------------------------------- 1 | # Practice: ASCII and Advanced Conversion Functions 2 | 3 | In this practice you will use the JavaScript built-in functions, 4 | `String.fromCharCode()` and `charCodeAt()` to convert ASCII. You will also use 5 | the `parseInt()` and `toString()` to convert number bases of binary to 6 | hexadecimal and vice versa. 7 | 8 | ## Set up 9 | 10 | - Download the starter at the bottom of this page. 11 | - Run `npm install` to install dependencies. 12 | - Run `npm test` to run specs. 13 | - Uncomment local specs to run local tests. 14 | 15 | ## Instructions 16 | 17 | Expect to utilize documentation to improve your understanding of these methods: 18 | 19 | - [`parseInt()` documentation][parseint-mdn] 20 | - [`toString()` documentation][tostring-mdn] 21 | - [`String.fromCharCode()` documentation][fromcharcode-mdn] 22 | - [`charCodeAt()` documentation][charcodeat-mdn] 23 | 24 | Use these built-in JavaScript functions to implement the following conversion 25 | functions: 26 | 27 | ### Using `parseInt()` and `toString()` 28 | 29 | - `binaryToHexadecimal(blob)` 30 | - Takes in a binary string argument and returns the equivalent hexadecimal 31 | string formatted to include `0x` prefix. 32 | - The first step will be to convert to a decimal using `parseInt()` 33 | 34 | - `hexadecimalToBinary(blob)` 35 | - Takes in a hexadecimal string argument and returns the equivalent binary 36 | string formatted to include `0b` prefix. 37 | - The first step will be to convert to a decimal using `parseInt()` 38 | 39 | ### Using `String.fromCharCode()` 40 | 41 | - `decimalToAscii(blob)` 42 | - Takes in a decimal number and returns the equivalent ASCII character. 43 | - `binaryToAscii(blob)` 44 | - Takes in a binary string and returns the equivalent ASCII character. 45 | - `hexadecimalToAscii(blob)` 46 | - Takes in a hexadecimal string and returns the equivalent ASCII character. 47 | 48 | ### Using `charCodeAt()` 49 | 50 | - `asciiToDecimal(blob)` 51 | - Takes in a string and returns an array of decimal char codes that 52 | represents each character. 53 | 54 | ## What you've learned 55 | 56 | You have learned how to use `String.fromCharCode()` and `charCodeAt()` to 57 | change a number to its equivalent ASCII character. You have also utilized 58 | `parseInt()` and `toString()` to handle multi-step conversions of binary to 59 | hexadecimal and hexadecimal to binary. 60 | 61 | 62 | [fromcharcode-mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode 63 | [charcodeat-mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charCodeAt 64 | [parseint-mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt 65 | [tostring-mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString 66 | -------------------------------------------------------------------------------- /week-5/d4-hash-tables-and-sets/practices/01-hash-tables/test/hash-table-pt1-spec.js: -------------------------------------------------------------------------------- 1 | const { expect } = require('chai'); 2 | 3 | const HashTable = require('../hash-table.js'); 4 | 5 | 6 | describe('Hash table constructor', () => { 7 | 8 | let hashTable; 9 | 10 | beforeEach(function () { 11 | 12 | hashTable = new HashTable(2); 13 | 14 | }); 15 | 16 | it('has count, capacity and data properties', () => { 17 | 18 | expect(hashTable.count).to.equal(0); 19 | expect(hashTable.capacity).to.equal(2); 20 | expect(hashTable.data instanceof Array).to.be.true; 21 | expect(hashTable.data.length).to.equal(2); 22 | 23 | expect(hashTable.data[0]).to.equal(null); 24 | expect(hashTable.data[1]).to.equal(null); 25 | 26 | }); 27 | 28 | it('can initialize to different sizes', () => { 29 | 30 | hashTable = new HashTable(4); 31 | 32 | expect(hashTable.count).to.equal(0); 33 | expect(hashTable.capacity).to.equal(4); 34 | expect(hashTable.data instanceof Array).to.be.true; 35 | expect(hashTable.data.length).to.equal(4); 36 | 37 | expect(hashTable.data[0]).to.equal(null); 38 | expect(hashTable.data[1]).to.equal(null); 39 | expect(hashTable.data[2]).to.equal(null); 40 | expect(hashTable.data[3]).to.equal(null); 41 | 42 | }); 43 | 44 | }); 45 | 46 | 47 | describe('Hash table methods', () => { 48 | 49 | let hashTable; 50 | 51 | beforeEach(function () { 52 | 53 | hashTable = new HashTable(2); 54 | 55 | }); 56 | 57 | it('hash method returns first 8 characters of sha256 hash as an integer', () => { 58 | 59 | // First 8 digits of sha256("A") are 0x559aead0 60 | expect(hashTable.hash("A")).to.equal(1436216016); 61 | 62 | // First 8 digits of sha256("B") are 0xdf7e70e 63 | expect(hashTable.hash("B")).to.equal(3749605605); 64 | 65 | // First 8 digits of sha256("C") are 0x6b23c0d5 66 | expect(hashTable.hash("C")).to.equal(1797505237); 67 | 68 | // First 8 digits of sha256("ABC") are 0xb5d4045c 69 | expect(hashTable.hash("ABC")).to.equal(3050570844); 70 | 71 | // First 8 digits of sha256("hello world") are 0xb94d27b9 72 | expect(hashTable.hash("hello world")).to.equal(3108841401); 73 | 74 | }); 75 | 76 | it('hashMod method returns the hash value modulo the number of buckets', () => { 77 | 78 | // 2 buckets 79 | expect(hashTable.hashMod("A")).to.equal(0); 80 | expect(hashTable.hashMod("B")).to.equal(1); 81 | expect(hashTable.hashMod("C")).to.equal(1); 82 | expect(hashTable.hashMod("ABC")).to.equal(0); 83 | 84 | expect(hashTable.hashMod("hello world")).to.equal(1); 85 | 86 | // 10 buckets 87 | hashTable = new HashTable(10); 88 | expect(hashTable.hashMod("A")).to.equal(6); 89 | expect(hashTable.hashMod("B")).to.equal(5); 90 | expect(hashTable.hashMod("C")).to.equal(7); 91 | expect(hashTable.hashMod("ABC")).to.equal(4); 92 | 93 | expect(hashTable.hashMod("hello world")).to.equal(1); 94 | 95 | }); 96 | 97 | }); 98 | --------------------------------------------------------------------------------