diff --git a/README.md b/README.md index 68f2b63..7dd83f1 100644 --- a/README.md +++ b/README.md @@ -27,23 +27,23 @@ This repository maintained by [Nick Scialli](https://twitter.com/nas5w) and powe - [Merge Sort](/src/algorithms/sorting/mergeSort.js) - [Quick Sort](/src/algorithms/sorting/quickSort.js) - - TODO: Bucket Sort + - [Bucket Sort](/src/algorithms/sorting/bucketSort.js) - [Heap Sort](/src/algorithms/sorting/heapSort.js) - [Counting Sort](/src/algorithms/sorting/countingSort.js) - [Bubble Sort](/src/algorithms/sorting/bubbleSort.js) - [Selection Sort](/src/algorithms/sorting/selectionSort.js) - [Insertion Sort](/src/algorithms/sorting/insertionSort.js) - - TODO: Shell Sort + - [Shell Sort](/src/algorithms/sorting/shellSort.js) - Searching - [Linear Search](https://github.com/nas5w/javascript-patterns/blob/master/src/algorithms/searching/linearSearch.js) - [Binary Search](https://github.com/nas5w/javascript-patterns/blob/master/src/algorithms/searching/binarySearch.js) - - TODO: Jump Search - - TODO: Interpolation Search - - TODO: Exponential Search + - [Jump Search](https://github.com/nas5w/javascript-patterns/blob/master/src/algorithms/searching/jumpSearch.js) + - [Interpolation Search](https://github.com/nas5w/javascript-patterns/blob/master/src/algorithms/searching/interpolationSearch.js) + - [Exponential Search](https://github.com/nas5w/javascript-patterns/blob/master/src/algorithms/searching/exponentialSearch.js) - TODO: Sublist Search (Search a linked list in another list) - - TODO: Fibonacci Search + - [Fibonacci Search](https://github.com/nas5w/javascript-patterns/blob/master/src/algorithms/searching/fibonacciSearch.js) - TODO: The Ubiquitous Binary Search ## Patterns diff --git a/src/patterns/facade/Course.js b/src/patterns/facade/Course.js new file mode 100644 index 0000000..86615b2 --- /dev/null +++ b/src/patterns/facade/Course.js @@ -0,0 +1,34 @@ +/* eslint-disable no-console */ +class Course { + constructor(data) { + this.name = data.name; + this.project = data.project; + this.completed = data.completed || false; + } +} + +const CourseServices = (() => { + return { + complete: Course => { + Course.completed = true; + console.log("Completing course", Course.name); + }, + save: Course => { + console.log("Saving course", Course.name); + } + }; +})(); + +const CourseServicesFacade = (() => { + const Complete = (Course) => { + CourseServices.complete(Course) + if (Course.completed) { + CourseServices.save(Course) + } + } + return { + CompleteMethod: Complete + } +})(); + +module.exports = { Course, CourseServicesFacade }; diff --git a/src/patterns/facade/main.js b/src/patterns/facade/main.js new file mode 100644 index 0000000..9d4918d --- /dev/null +++ b/src/patterns/facade/main.js @@ -0,0 +1,13 @@ +/* eslint-disable no-console */ +const {Course, CourseServicesFacade} = require("./Course"); + +const myCourse = new Course({ + name: "Design Pattern", + project: "Facade Design Pattern App" +}); + +console.log("myCourse-1: ", myCourse); + +CourseServicesFacade.CompleteMethod(myCourse) + +console.log("myCourse-2: ", myCourse)