├── .gitignore ├── Additional-Resources └── README.md ├── LICENSE ├── Practical Exams ├── 02-March-2017 │ ├── README.md │ ├── package.json │ ├── task │ │ └── task.js │ └── tests │ │ └── tests.js ├── 09-July-2015 │ ├── README.md │ ├── package.json │ ├── tasks │ │ ├── solution-classical-inheritance-doncho.js │ │ ├── solution-cuki-feb-2017.js │ │ ├── solution-doncho.js │ │ ├── solution-es2015-classes-cuki.js │ │ ├── solution-es2015-doncho.js │ │ ├── solution-evlogi.js │ │ └── solution.js │ └── tests │ │ └── tests-solution.js ├── 10-September-2016 │ ├── task-1 │ │ ├── README.html │ │ ├── README.md │ │ ├── package.json │ │ ├── task │ │ │ ├── .vscode │ │ │ │ └── launch.json │ │ │ ├── app.js │ │ │ ├── solution-9-feb-2017.js │ │ │ ├── solution-koce.js │ │ │ └── solution.js │ │ └── tests │ │ │ └── tests-solution.js │ └── task-2 │ │ ├── README.html │ │ ├── README.md │ │ ├── package.json │ │ ├── task │ │ ├── solution-9-feb-2017.js │ │ ├── solution-cuki.js │ │ ├── solution-typescript.ts │ │ └── solution.js │ │ └── tests │ │ └── tests.js └── 23-February-2017 │ ├── README.md │ ├── package.json │ ├── task │ └── task.js │ └── tests │ ├── 01-sample-tests.js │ └── 02-behaviour-tests.js ├── README.md ├── Sample Exams └── audio-player │ ├── README.md │ ├── package.json │ ├── tasks │ ├── solution-doncho.js │ ├── solution-ivaylo.js │ └── task-1.js │ └── tests │ ├── task-1-tests-playlist.js │ ├── task-1-tests.coffee │ ├── task-1-tests.js │ └── task-1-tests.js.map ├── Topics ├── 00. Course-Introduction │ ├── README.md │ ├── imgs │ │ ├── pic00.png │ │ ├── pic01.png │ │ ├── pic02.png │ │ ├── pic03.png │ │ ├── pic04.png │ │ ├── pic05.png │ │ ├── pic06.png │ │ ├── pic07.png │ │ ├── pic08.png │ │ ├── pic09.png │ │ ├── pic10.png │ │ ├── pic11.png │ │ ├── pic12.png │ │ ├── pic13.png │ │ ├── pic14.png │ │ ├── pic15.png │ │ ├── pic16.png │ │ ├── pic17.png │ │ ├── pic18.png │ │ ├── pic19.png │ │ ├── pic20.png │ │ ├── pic21.png │ │ ├── pic22.png │ │ ├── pic23.png │ │ ├── pic24.png │ │ ├── pic25.png │ │ ├── pic26.png │ │ ├── pic27.png │ │ ├── pic28.png │ │ ├── pic29.png │ │ ├── pic30.png │ │ ├── pic31.png │ │ ├── pic32.png │ │ ├── pic33.png │ │ ├── pic34.png │ │ ├── pic37.png │ │ ├── pic38.png │ │ ├── pic39.png │ │ ├── pic40.png │ │ ├── pic41.png │ │ └── pic42.png │ └── index.html ├── 01. Functions-and-Function-Expressions │ ├── README.md │ ├── demos │ │ ├── .vscode │ │ │ └── launch.json │ │ ├── 01. functions │ │ │ ├── functions.html │ │ │ └── functions.js │ │ ├── 02. function-object │ │ │ ├── function-object.html │ │ │ └── function-object.js │ │ ├── 03. function-declarations │ │ │ ├── function-declarations.html │ │ │ └── function-declarations.js │ │ ├── 04. function-expressions │ │ │ ├── function-expressions.html │ │ │ └── function-expressions.js │ │ ├── 05. function-constructor │ │ │ ├── function-constructor.html │ │ │ └── function-constructor.js │ │ ├── 06. expressions-vs-declarations │ │ │ ├── expressions-vs-declarations.html │ │ │ └── expressions-vs-declarations.js │ │ ├── 07. function-methods │ │ │ ├── function-methods.html │ │ │ └── function-methods.js │ │ ├── 08. recursion-factorial │ │ │ ├── recursion-factorial.html │ │ │ └── recursion-factorial.js │ │ ├── 09. recursion-traversing-dom │ │ │ ├── recursion-traversing-dom.html │ │ │ └── recursion-traversing-dom.js │ │ ├── 10. buggy-recursin-expressions │ │ │ ├── buggy-recursin-expressions.html │ │ │ └── buggy-recursin-expressions.js │ │ ├── 11. recursiоn-expressions │ │ │ ├── recursiоn-expressions.html │ │ │ └── recursiоn-expressions.js │ │ ├── 14. nested-functions │ │ │ ├── nested-functions.html │ │ │ └── nested-functions.js │ │ ├── 15. immediately-invoked-function-expressions │ │ │ ├── immediately-invoked-function-expressions.html │ │ │ └── immediately-invoked-function-expressions.js │ │ └── 18. closures-usage-jquery-prototype │ │ │ ├── closures-usage-jquery-prototype.html │ │ │ ├── closures-usage-jquery-prototype.js │ │ │ └── libs │ │ │ ├── jquery.min.js │ │ │ └── prototype.min.js │ ├── homework │ │ ├── README.md │ │ ├── package.json │ │ ├── tasks │ │ │ ├── task-1.js │ │ │ └── task-2.js │ │ └── tests │ │ │ ├── tests-task-1.js │ │ │ └── tests-task-2.js │ ├── imgs │ │ ├── pic00.png │ │ ├── pic01.png │ │ ├── pic02.png │ │ ├── pic03.png │ │ ├── pic04.png │ │ ├── pic05.png │ │ ├── pic06.png │ │ ├── pic07.png │ │ ├── pic08.png │ │ ├── pic09.png │ │ ├── pic11.png │ │ ├── pic12.png │ │ ├── pic13.png │ │ ├── pic14.png │ │ ├── pic15.png │ │ ├── pic16.png │ │ ├── pic17.png │ │ ├── pic18.png │ │ ├── pic19.png │ │ ├── pic20.png │ │ ├── pic21.png │ │ ├── pic22.png │ │ └── pic23.png │ └── index.html ├── 02. Closures-and-Scope │ ├── README.md │ ├── demos │ │ ├── 1. function-scope.js │ │ ├── 1. scopes-global.js │ │ ├── 3. scope-chain.js │ │ ├── 4. block-scope-let.js │ │ ├── 5. closures.js │ │ └── 6. closures-usage.js │ ├── homework │ │ ├── README.md │ │ ├── package.json │ │ ├── tasks │ │ │ └── task-1.js │ │ └── tests │ │ │ └── tests-task-1.js │ ├── imgs │ │ ├── closures.png │ │ ├── pic01.png │ │ └── pic03.png │ └── index.html ├── 03. Modules-and-Patterns │ ├── README.md │ ├── demos │ │ ├── 1. module.js │ │ ├── 2. revealing-module.js │ │ ├── 3. revealing-module.js │ │ └── index.html │ ├── homework │ │ ├── README.md │ │ ├── package.json │ │ ├── tasks │ │ │ └── task-1.js │ │ └── tests │ │ │ ├── tests-task-1-bgcoder.js │ │ │ ├── tests-task-1-compiled.js │ │ │ ├── tests-task-1-compiled.js.map │ │ │ └── tests-task-1.js │ ├── imgs │ │ ├── pic00.png │ │ ├── pic01.png │ │ ├── pic02.png │ │ ├── pic03.png │ │ ├── pic04.png │ │ ├── pic05.png │ │ ├── pic06.png │ │ ├── pic07.png │ │ ├── pic08.png │ │ ├── pic09.png │ │ ├── pic10.png │ │ ├── pic11.png │ │ ├── pic12.png │ │ ├── pic13.png │ │ ├── pic14.png │ │ ├── pic15.png │ │ ├── pic16.png │ │ ├── pic17.png │ │ ├── pic18.png │ │ └── pic19.png │ └── index.html ├── 04. Classes-and-Class-Constructors │ ├── README.md │ ├── demos │ │ └── demo.js │ ├── homework │ │ └── README.md │ ├── imgs │ │ └── es6.png │ └── index.html ├── 05. Class-Methods-and-Properties │ ├── README.md │ ├── demos │ │ └── demo.js │ ├── homework │ │ ├── README.md │ │ └── task-1 │ │ │ ├── README.md │ │ │ ├── package.json │ │ │ ├── task │ │ │ └── task-1.js │ │ │ └── tests │ │ │ └── tests.js │ └── index.html ├── 06. Class-Inheritance │ ├── README.md │ ├── demos │ │ └── pet-store.js │ ├── homework │ │ └── README.md │ └── index.html └── 07. ES2015-Features │ ├── README.md │ ├── demos │ ├── 00. demo-compiled.js │ ├── 00. demo-compiled.js.map │ ├── 00. demo.js │ ├── 01. let and const-compiled.js │ ├── 01. let and const-compiled.js.map │ ├── 01. let and const.js │ ├── 02. for-of loop-compiled.js │ ├── 02. for-of loop-compiled.js.map │ ├── 02. for-of loop.js │ ├── 03. templated string-compiled.js │ ├── 03. templated string-compiled.js.map │ ├── 03. templated string.js │ ├── 04. classes and inheritance-compiled.js │ ├── 04. classes and inheritance-compiled.js.map │ ├── 04. classes and inheritance.js │ ├── 05. arrow functions-compiled.js │ ├── 05. arrow functions-compiled.js.map │ ├── 05. arrow functions.js │ ├── 06. destructuring assignments-compiled.js │ ├── 06. destructuring assignments-compiled.js.map │ ├── 06. destructuring assignments.js │ ├── 07. maps and sets-compiled.js │ ├── 07. maps and sets-compiled.js.map │ ├── 07. maps and sets.js │ ├── 09. extended parameter handling-compiled.js │ ├── 09. extended parameter handling-compiled.js.map │ ├── 09. extended parameter handling.js │ ├── 10. Symbol type-compiled.js │ ├── 10. Symbol type-compiled.js.map │ ├── 10. Symbol type.js │ └── live-demos │ │ ├── features-Symbol-and-iterators.js │ │ ├── features-destructuring.js │ │ ├── features-events.js │ │ ├── features-features-arrays.js │ │ ├── features-function-params.js │ │ ├── features-generators.js │ │ ├── features-numbers.js │ │ ├── features-objects.js │ │ ├── features-promises.js │ │ ├── features-strings.js │ │ └── index.html │ └── index.html └── Workshops ├── 21-February-2017 ├── README.md ├── package.json ├── tasks │ └── task-1.js └── tests │ └── task-1-tests-playlist.js ├── 31-January-2017 ├── README.md ├── package.json ├── task │ └── solution.js └── tests │ └── tests-solution.js └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | build/ 21 | bld/ 22 | [Bb]in/ 23 | [Oo]bj/ 24 | 25 | # Visual Studo 2015 cache/options directory 26 | .vs/ 27 | 28 | # MSTest test Results 29 | [Tt]est[Rr]esult*/ 30 | [Bb]uild[Ll]og.* 31 | 32 | # NUNIT 33 | *.VisualState.xml 34 | TestResult.xml 35 | 36 | # Build Results of an ATL Project 37 | [Dd]ebugPS/ 38 | [Rr]eleasePS/ 39 | dlldata.c 40 | 41 | *_i.c 42 | *_p.c 43 | *_i.h 44 | *.ilk 45 | *.meta 46 | *.obj 47 | *.pch 48 | *.pdb 49 | *.pgc 50 | *.pgd 51 | *.rsp 52 | *.sbr 53 | *.tlb 54 | *.tli 55 | *.tlh 56 | *.tmp 57 | *.tmp_proj 58 | *.log 59 | *.vspscc 60 | *.vssscc 61 | .builds 62 | *.pidb 63 | *.svclog 64 | *.scc 65 | 66 | # Chutzpah Test files 67 | _Chutzpah* 68 | 69 | # Visual C++ cache files 70 | ipch/ 71 | *.aps 72 | *.ncb 73 | *.opensdf 74 | *.sdf 75 | *.cachefile 76 | 77 | # Visual Studio profiler 78 | *.psess 79 | *.vsp 80 | *.vspx 81 | 82 | # TFS 2012 Local Workspace 83 | $tf/ 84 | 85 | # Guidance Automation Toolkit 86 | *.gpState 87 | 88 | # ReSharper is a .NET coding add-in 89 | _ReSharper*/ 90 | *.[Rr]e[Ss]harper 91 | *.DotSettings.user 92 | 93 | # JustCode is a .NET coding addin-in 94 | .JustCode 95 | 96 | # TeamCity is a build add-in 97 | _TeamCity* 98 | 99 | # DotCover is a Code Coverage Tool 100 | *.dotCover 101 | 102 | # NCrunch 103 | _NCrunch_* 104 | .*crunch*.local.xml 105 | 106 | # MightyMoose 107 | *.mm.* 108 | AutoTest.Net/ 109 | 110 | # Web workbench (sass) 111 | .sass-cache/ 112 | 113 | # Installshield output folder 114 | [Ee]xpress/ 115 | 116 | # DocProject is a documentation generator add-in 117 | DocProject/buildhelp/ 118 | DocProject/Help/*.HxT 119 | DocProject/Help/*.HxC 120 | DocProject/Help/*.hhc 121 | DocProject/Help/*.hhk 122 | DocProject/Help/*.hhp 123 | DocProject/Help/Html2 124 | DocProject/Help/html 125 | 126 | # Click-Once directory 127 | publish/ 128 | 129 | # Publish Web Output 130 | *.[Pp]ublish.xml 131 | *.azurePubxml 132 | # TODO: Comment the next line if you want to checkin your web deploy settings 133 | # but database connection strings (with potential passwords) will be unencrypted 134 | *.pubxml 135 | *.publishproj 136 | 137 | # NuGet Packages 138 | *.nupkg 139 | # The packages folder can be ignored because of Package Restore 140 | **/packages/* 141 | # except build/, which is used as an MSBuild target. 142 | !**/packages/build/ 143 | # Uncomment if necessary however generally it will be regenerated when needed 144 | #!**/packages/repositories.config 145 | 146 | # Windows Azure Build Output 147 | csx/ 148 | *.build.csdef 149 | 150 | # Windows Store app package directory 151 | AppPackages/ 152 | 153 | # Others 154 | *.[Cc]ache 155 | ClientBin/ 156 | [Ss]tyle[Cc]op.* 157 | ~$* 158 | *~ 159 | *.dbmdl 160 | *.dbproj.schemaview 161 | *.pfx 162 | *.publishsettings 163 | node_modules/ 164 | bower_components/ 165 | 166 | # RIA/Silverlight projects 167 | Generated_Code/ 168 | 169 | # Backup & report files from converting an old project file 170 | # to a newer Visual Studio version. Backup files are not needed, 171 | # because we have git ;-) 172 | _UpgradeReport_Files/ 173 | Backup*/ 174 | UpgradeLog*.XML 175 | UpgradeLog*.htm 176 | 177 | # SQL Server files 178 | *.mdf 179 | *.ldf 180 | 181 | # Business Intelligence projects 182 | *.rdl.data 183 | *.bim.layout 184 | *.bim_*.settings 185 | 186 | # Microsoft Fakes 187 | FakesAssemblies/ 188 | 189 | # Node.js Tools for Visual Studio 190 | .ntvs_analysis.dat 191 | 192 | # Visual Studio 6 build log 193 | *.plg 194 | 195 | # Visual Studio 6 workspace options file 196 | *.opt 197 | -------------------------------------------------------------------------------- /Additional-Resources/README.md: -------------------------------------------------------------------------------- 1 | # Additional Resources 2 | 3 | - Babel 4 | - [Video course](https://app.pluralsight.com/library/courses/babel-get-started/table-of-contents) 5 | - ES 2015 overview 6 | - [Article](https://github.com/lukehoban/es6features#readme) 7 | - [Article](https://babeljs.io/docs/learn-es2015/) 8 | - [Video Course](https://app.pluralsight.com/library/courses/nodejs-es6-web-apps/table-of-contents) 9 | - OOP in JavaScript with ES2015 10 | - [Video Course](https://app.pluralsight.com/library/courses/javascript-es6-object-oriented-programming/table-of-contents) 11 | - [Article MDN](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Classes) 12 | - [ES2015 Classes essentials](http://exploringjs.com/es6/ch_classes.html) 13 | - [Rich article on when and why you should avoid ES2015 classes](https://github.com/joshburgess/not-awesome-es6-classes) 14 | - Mixins 15 | - [Article MDN] (https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Classes#Mix-ins) 16 | - [Article](http://justinfagnani.com/2015/12/21/real-mixins-with-javascript-classes/) 17 | - Modules 18 | - [Video Course](https://app.pluralsight.com/library/courses/javascript-module-fundamentals/table-of-contents) 19 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Telerik Academy 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /Practical Exams/02-March-2017/README.md: -------------------------------------------------------------------------------- 1 | # Hardware Store 2 | 3 | Implement functionality for hardware stores. 4 | 5 | _Notes:_ 6 | - There is no need to specify an error message when **throwing** an `Error`. 7 | - Use single quotes for strings: `'string'` 8 | 9 | ## Class descriptions 10 | 11 | ### `class Product` 12 | - Properties 13 | - `id` - should be generated automatically and be different for different products 14 | - `manufacturer` - string with length between 1 and 20 symbols (inclusive) 15 | - `model` - string with length between 1 and 20 symbols (inclusive) 16 | - `price` - positive, non-zero number 17 | - **Throw** if any of the properties are invalid 18 | - Methods: 19 | - `getLabel()` - returns a string: what should be written on the label 20 | - read on :) 21 | 22 | ### `class SmartPhone` extends `Product` 23 | - Properties: 24 | - `screenSize` - positive, non-zero number 25 | - `operatingSystem` - string with length between 1 and 10 symbols (inclusive) 26 | - **Throw** if any of the properties are invalid 27 | - Methods: 28 | - `getLabel()` - returns a string: what should be written on the label 29 | - `SmartPhone - MANUFACTURER MODEL - **PRICE**` 30 | 31 | ### `class Charger` extends `Product` 32 | - Properties: 33 | - `outputVoltage` - number between 5 and 20 (inclusive) 34 | - `outputCurrent` - number between 100 and 3000 (inclusive) 35 | - its in milliamperes if you are asking 36 | - **Throw** if any of the properties are invalid 37 | - Methods: 38 | - `getLabel()` - returns a string: what should be written on the label 39 | - `Charger - MANUFACTURER MODEL - **PRICE**` 40 | 41 | ### `class Router` extends `Product` 42 | - Properties: 43 | - `wifiRange` - positive, non-zero number 44 | - `lanPorts` - positive, non-zero **integer** number 45 | - **Throw** if any of the properties are invalid 46 | - Methods: 47 | - `getLabel()` - returns a string: what should be written on the label 48 | - `Router - MANUFACTURER MODEL - **PRICE**` 49 | 50 | ### `class Headphones` extends `Product` 51 | - Properties: 52 | - `quality` - string, should be either `high`, `mid` or `low` 53 | - **Throw** if `quality` is invalid 54 | - `hasMicrophone` - boolean 55 | - convert true-like javascript values to `true` and false-like to `false` 56 | - Methods: 57 | - `getLabel()` - returns a string: what should be written on the label 58 | - `Headphones - MANUFACTURER MODEL - **PRICE**` 59 | 60 | ### `class HardwareStore` 61 | - Properties: 62 | - `name` - string with length between 1 and 20 symbols (inclusive) 63 | - **Throw** if invalid 64 | - `products` - array of unique products currently in storage 65 | - should be empty when the store is created 66 | - Methods: 67 | - `stock(product, quantity)` - adds new products 68 | - `product` should be a valid `Product` instance 69 | - `quantity` should be a positive, non-zero integer number 70 | - **Throw otherwise** 71 | - **Should provide chaining** 72 | - `sell(productId, quantity)` - sells products 73 | - `quantity` should be a positive, non-zero integer number 74 | - there should be at least `quantity` products with id `productId` available in the store 75 | - **Throw otherwise** 76 | - **Should provide chaining** 77 | - `getSold()` - returns the amount of money earned from selling in the current store 78 | - `search(pattern)` - returns an array of unique products containing `pattern` in their model or manufacturer name 79 | - perform **case insensitive** search 80 | - each element in the array should have 2 keys: 81 | - `product` - the product instance 82 | - `quantity` - the available quantity of that product 83 | - `search(options)` - advanced search, same as above 84 | - options is an object with **optional** keys: 85 | - `manufacturerPattern` - string, should be contained in manufacterures **(case sensitive)** 86 | - `modelPattern` - string, should be contained in models **(case sensitive)** 87 | - `type` - string - `SmartPhone`, `Charger`, `Router` or `Headphones` - the product should be of the specified type 88 | - `minPrice` - number - the product should not be cheaper than `minPrice` 89 | - `maxPrice` - number - the product should not be more expensive than `maxPrice` 90 | 91 | ## Sample usage 92 | 93 | ```javascript 94 | const result = solve(); 95 | 96 | const phone = result.getSmartPhone('HTC', 'One', 903, 5, 'Android'); 97 | 98 | console.log(phone.getLabel()); // SmartPhone - HTC One - **903** 99 | 100 | const headphones = result.getHeadphones('Sennheiser', 'PXC 550 Wireless', 340, 'high', false); 101 | const store = result.getHardwareStore('Magazin'); 102 | 103 | store.stock(phone, 1) 104 | .stock(headphones, 15); 105 | 106 | console.log(store.search('senn')); 107 | /* 108 | [ { product: 109 | Headphones { ... }, 110 | quantity: 15 } ] 111 | */ 112 | 113 | console.log(store.search({type: 'SmartPhone', maxPrice: 1000}); 114 | /* 115 | [ { product: 116 | SmartPhone { ... }, 117 | quantity: 1 } ] 118 | */ 119 | 120 | console.log(store.search({type: 'SmartPhone', maxPrice: 900}); 121 | /* [] */ 122 | 123 | store.sell(headphones.id, 2); 124 | console.log(store.getSold()); // 680 125 | ``` 126 | 127 | ## Solution template 128 | 129 | ```javascript 130 | function solve() { 131 | // Your classes 132 | 133 | return { 134 | getSmartPhone(manufacturer, model, price, screenSize, operatingSystem) { 135 | // returns SmarhPhone instance 136 | }, 137 | getCharger(manufacturer, model, price, outputVoltage, outputCurrent) { 138 | // returns Charger instance 139 | }, 140 | getRouter(manufacturer, model, price, wifiRange, lanPorts) { 141 | // returns Router instance 142 | }, 143 | getHeadphones(manufacturer, model, price, quality, hasMicrophone) { 144 | // returns Headphones instance 145 | }, 146 | getHardwareStore(name) { 147 | // returns HardwareStore instance 148 | } 149 | }; 150 | } 151 | 152 | // Submit the code above this line in bgcoder.com 153 | module.exports = solve; // DO NOT SUBMIT THIS LINE 154 | ``` 155 | -------------------------------------------------------------------------------- /Practical Exams/02-March-2017/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "exam", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "mocha -R spec tests" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "devDependencies": { 12 | "chai": "^3.5.0", 13 | "mocha": "^3.2.0" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Practical Exams/09-July-2015/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "test-driven-hw-mocha", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "mocha -R spec tests" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "devDependencies": { 12 | "chai": "^3.0.0", 13 | "mocha": "^3.0.2" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Practical Exams/09-July-2015/tasks/solution.js: -------------------------------------------------------------------------------- 1 | function solve() { 2 | return { 3 | getBook: function (name, isbn, genre, description) { 4 | // return a book instance 5 | }, 6 | getMedia: function (name, rating, duration, description) { 7 | // return a media instance 8 | }, 9 | getBookCatalog: function (name) { 10 | // return a book catalog instance 11 | }, 12 | getMediaCatalog: function (name) { 13 | // return a media catalog instance 14 | } 15 | }; 16 | } 17 | 18 | module.exports = solve; 19 | -------------------------------------------------------------------------------- /Practical Exams/10-September-2016/task-1/README.md: -------------------------------------------------------------------------------- 1 | # Carts and Products 2 | 3 | - Implement a functionality to serve a Shopping Center 4 | - Export a class **`Product`** 5 | - Export a class **`ShoppingCart`** 6 | 7 | # Classes and functionality: 8 | 9 | ### `Product` 10 | 11 | - Has the following methods and properties 12 | - `constructor` 13 | - **Parameters** 14 | - `productType` 15 | - `name` 16 | - `price` 17 | - _Example_: 18 | - `new Product("Sweets", "Shokolad Milka", 2)`; 19 | - **Public properties**: 20 | - `productType`: `String` 21 | - `name`: `String` 22 | - `price`: `Number` 23 | 24 | ### `ShoppingCart` 25 | 26 | - Has the following methods and properties 27 | - `constructor` 28 | - **Parameters** 29 | - No parameters 30 | - _Example_: 31 | - `new ShoppingCart()`; 32 | - **Public properties**: 33 | - `products`: `Array` 34 | - **Public methods**: 35 | - `add(product)` 36 | - **Parameters**: 37 | - A `Product` or Product-like object 38 | - **Behavior**: 39 | - Adds the `product` to the `products` array in this `ShoppingCart` instance 40 | - A product can be added many times into the same `ShoppingCart` instance 41 | - Should provide chaining 42 | - `remove(product)` 43 | - **Parameters** 44 | - a `Product` or Product-like object 45 | - **Behavior**: 46 | - Removes the left-most object from the `products` array in this `ShoppingCart` instance, that has the same `name`, `price` and `productType` 47 | - **Throws** when: 48 | - The `ShoppingCart` instance does not contain this product 49 | - There are not products in the `ShoppingCart` instance 50 | - `showCost()` 51 | - **Parameters** 52 | - No parameters 53 | - **Behavior**: 54 | - Returns the sum from the costs of all products in this `ShoppingCart` instance 55 | - Returns `0` when there are no products in this `ShoppingCart` instance 56 | - `showProductTypes()` 57 | - **Parameters** 58 | - No parameters 59 | - **Behavior**: 60 | - Returns the **unique productTypes** of the products added to this `ShoppingCart` instance 61 | - The returned product types must be **sorted alphabetically** 62 | - Returns an empty array when there are no products in this `ShoppingCart` instance 63 | - `getInfo()` 64 | - **Parameters** 65 | - No parameters 66 | - **Behavior**: 67 | - Returns an object containing information about the products in this `ShoppingCart` instance. The returned object has two properties: 68 | - `products`: Groups products by their name 69 | - For each unique product name there creates an element: 70 | - The `name` of the products 71 | - Their total cost 72 | - The quantity of products with this name in the `ShoppingCart` instance 73 | - `totalPrice`: The total price of all products in this `ShoppingCart` instance 74 | - Returns an object with `totalPrice` equal to `0` and `products` - an empty array, when no products in this `ShoppingCart` instance 75 | 76 | # Solution template 77 | 78 | ```javascript 79 | 80 | function solve(){ 81 | class Product{ 82 | /* .... */ 83 | } 84 | 85 | class ShoppingCart { 86 | /* .... */ 87 | } 88 | return { 89 | Product, ShoppingCart 90 | }; 91 | } 92 | ``` 93 | 94 | # Example usage: 95 | 96 | ```javascript 97 | let {Product, ShoppingCart} = solve(); 98 | 99 | let cart = new ShoppingCart(); 100 | 101 | let pr1 = new Product("Sweets", "Shokolad Milka", 2); 102 | cart.add(pr1); 103 | console.log(cart.showCost()); 104 | //prints `2` 105 | 106 | let pr2 = new Product("Groceries", "Salad", 0.5); 107 | cart.add(pr2); 108 | cart.add(pr2); 109 | console.log(cart.showCost()); 110 | //prints `3` 111 | 112 | console.log(cart.showProductTypes()); 113 | //prints ["Sweets", "Groceries"] 114 | 115 | console.log(cart.getInfo()); 116 | /* prints 117 | { 118 | totalPrice: 3 119 | products: [{ 120 | name: "Salad", 121 | totalPrice: 1, 122 | quantity: 2 123 | }, { 124 | name: "Shokolad Milka", 125 | totalPrice: 2, 126 | quantity: 1 127 | }] 128 | } 129 | */ 130 | 131 | cart.remove({name:"salad", productType: "Groceries", price: 0.5}) 132 | //throws: "salad" is not equal to "Salad" 133 | 134 | cart.remove({name:"Salad", productType: "Groceries", price: 0.5}) 135 | console.log(cart.getInfo()); 136 | /* prints 137 | { 138 | totalPrice: 2.5 139 | products: [{ 140 | name: "Salad", 141 | totalPrice: 0.5, 142 | quantity: 1 143 | }, { 144 | name: "Shokolad Milka", 145 | totalPrice: 2, 146 | quantity: 1 147 | }] 148 | } 149 | */ 150 | ``` -------------------------------------------------------------------------------- /Practical Exams/10-September-2016/task-1/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "test-driven-hw-mocha", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "mocha -R spec ./tests" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "chai": "^3.5.0", 13 | "mocha": "^3.0.2" 14 | } 15 | } -------------------------------------------------------------------------------- /Practical Exams/10-September-2016/task-1/task/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "name": "Launch", 6 | "type": "node", 7 | "request": "launch", 8 | "program": "${workspaceRoot}/app.js", 9 | "stopOnEntry": false, 10 | "args": [], 11 | "cwd": "${workspaceRoot}", 12 | "preLaunchTask": null, 13 | "runtimeExecutable": null, 14 | "runtimeArgs": [ 15 | "--nolazy" 16 | ], 17 | "env": { 18 | "NODE_ENV": "development" 19 | }, 20 | "externalConsole": false, 21 | "sourceMaps": false, 22 | "outDir": null 23 | }, 24 | { 25 | "name": "Attach", 26 | "type": "node", 27 | "request": "attach", 28 | "port": 5858, 29 | "address": "localhost", 30 | "restart": false, 31 | "sourceMaps": false, 32 | "outDir": null, 33 | "localRoot": "${workspaceRoot}", 34 | "remoteRoot": null 35 | }, 36 | { 37 | "name": "Attach to Process", 38 | "type": "node", 39 | "request": "attach", 40 | "processId": "${command.PickProcess}", 41 | "port": 5858, 42 | "sourceMaps": false, 43 | "outDir": null 44 | } 45 | ] 46 | } -------------------------------------------------------------------------------- /Practical Exams/10-September-2016/task-1/task/app.js: -------------------------------------------------------------------------------- 1 | /* globals require console*/ 2 | 3 | "use strict"; 4 | 5 | let { ShoppingCart, Product } = require("./task-2")(); 6 | 7 | let sc = new ShoppingCart(); 8 | 9 | 10 | let p = new Product("food", "Bread", "1"); 11 | 12 | sc.add(new Product("beverages", "Whiskey", "25")); 13 | 14 | sc.add(p); 15 | sc.add(p); 16 | sc.add(p); 17 | sc.add(p); 18 | 19 | console.log(sc.showCost()); 20 | console.log(sc.showProductTypes()); 21 | 22 | console.log(sc.getInfo()); 23 | 24 | sc.remove(p); 25 | 26 | console.log(sc.getInfo()); -------------------------------------------------------------------------------- /Practical Exams/10-September-2016/task-1/task/solution-9-feb-2017.js: -------------------------------------------------------------------------------- 1 | function solve() { 2 | class Product { 3 | constructor(productType, name, price) { 4 | this._productType = productType; 5 | this._name = name; 6 | this._price = price; 7 | } 8 | 9 | get productType() { 10 | return this._productType; 11 | } 12 | get name() { 13 | return this._name; 14 | } 15 | get price() { 16 | return this._price; 17 | } 18 | } 19 | 20 | class ShoppingCart { 21 | constructor() { 22 | this._products = []; 23 | } 24 | 25 | get products() { 26 | return this._products; 27 | // return this._products.slice(); 28 | } 29 | 30 | add(product) { 31 | this.products.push(new Product(product.productType, product.name, product.price)); 32 | return this; 33 | } 34 | 35 | remove(product) { 36 | const index = this.products.findIndex(p => p.name === product.name && p.productType === product.productType && p.price === product.price); 37 | 38 | if(index < 0) { 39 | throw 'Product not found'; 40 | } 41 | 42 | this.products.splice(index, 1); 43 | 44 | return this; 45 | } 46 | 47 | showCost() { 48 | return this.products.reduce((cost, product) => cost + product.price, 0); 49 | } 50 | 51 | showProductTypes() { 52 | /*const uniqTypes = []; 53 | this.products.forEach(function(p) { 54 | if(uniqTypes.indexOf(p.productType) < 0) { 55 | uniqTypes.push(p.productType); 56 | } 57 | }); 58 | 59 | return uniqTypes.sort();*/ 60 | 61 | /* 62 | return this.products.map(p => p.productType) 63 | .sort() 64 | .filter((p, i, ps) => i === 0 || p !== ps[i - 1]); 65 | */ 66 | 67 | const uniqTypesObj = {}; 68 | this.products.forEach(p => uniqTypesObj[p.productType] = true); 69 | return Object.keys(uniqTypesObj).sort(); 70 | } 71 | 72 | getInfo() { 73 | /* 74 | const uniqNames = this.products.map(p => p.name) 75 | .sort() 76 | .filter((p, i, ps) => i === 0 || p !== ps[i - 1]) 77 | .map(name => { 78 | const withThisName = this.products.filter(p => p.name === name); 79 | 80 | return { 81 | name: name, 82 | quantity: withThisName.length, 83 | totalPrice: withThisName.reduce((cost, product) => cost + product.price, 0) 84 | }; 85 | }); 86 | 87 | return { 88 | this.products: uniqNames, 89 | totalPrice: showCost() 90 | } 91 | */ 92 | 93 | const groupedByName = {}; 94 | 95 | this.products.forEach(p => { 96 | if(groupedByName.hasOwnProperty(p.name)) { 97 | groupedByName[p.name].quantity += 1; 98 | groupedByName[p.name].totalPrice += p.price; 99 | } 100 | else { 101 | groupedByName[p.name] = { 102 | name: p.name, 103 | quantity: 1, 104 | totalPrice: p.price 105 | }; 106 | } 107 | }); 108 | 109 | const groups = Object.keys(groupedByName) 110 | .sort() 111 | .map(n => { 112 | return { 113 | name: n, 114 | quantity: groupedByName[n].quantity, 115 | totalPrice: groupedByName[n].totalPrice 116 | }; 117 | }); 118 | 119 | return { 120 | //products: Object.values(groupedByName).sort(x => x.name), 121 | products: groups, 122 | totalPrice: this.showCost() 123 | } 124 | } 125 | } 126 | 127 | return { 128 | Product: Product, 129 | ShoppingCart: ShoppingCart 130 | } 131 | } 132 | 133 | module.exports = solve; 134 | -------------------------------------------------------------------------------- /Practical Exams/10-September-2016/task-1/task/solution-koce.js: -------------------------------------------------------------------------------- 1 | function solve() { 2 | 'use strict' 3 | 4 | class Product { 5 | constructor(productType, name, price) { 6 | this.productType = productType 7 | this.name = name 8 | this.price = Number(price) 9 | } 10 | equals(otherProduct) { 11 | return (this.name === otherProduct.name) && 12 | (this.productType === otherProduct.productType) && 13 | (this.price === otherProduct.price) 14 | } 15 | } 16 | 17 | class ShoppingCart { 18 | constructor() { 19 | this.products = [] 20 | } 21 | 22 | add(product) { 23 | this.products.push(product) 24 | return this 25 | } 26 | 27 | remove(product) { 28 | const indexOfProduct = this.products.findIndex(p => p.equals(product)) 29 | 30 | if (indexOfProduct === -1) { 31 | throw new Error('Cannot remove product that is not in the shopping cart!') 32 | } 33 | 34 | return this.products.splice(indexOfProduct, 1) 35 | } 36 | 37 | showCost() { 38 | return this.products.reduce((partialCost, currentProduct) => partialCost + currentProduct.price, 0) 39 | } 40 | 41 | showProductTypes() { 42 | const typesMap = {} 43 | 44 | for(const prod of this.products) { 45 | typesMap[prod.productType] = true 46 | } 47 | 48 | return Object.keys(typesMap).sort((first, second) => first.localeCompare(second)) 49 | } 50 | 51 | getInfo() { 52 | const productMap = {} 53 | 54 | for (const p of this.products) { 55 | if (!productMap[p.name]) { 56 | productMap[p.name] = { 57 | name: p.name, 58 | totalPrice: 0, 59 | quantity: 0 60 | } 61 | } 62 | 63 | productMap[p.name].totalPrice += p.price 64 | productMap[p.name].quantity += 1 65 | } 66 | 67 | const products = Object.keys(productMap).map(groupName => productMap[groupName]), 68 | totalPrice = products.reduce((partialPrice, currentProductGroup) => partialPrice + currentProductGroup.totalPrice, 0) 69 | 70 | return { 71 | products, 72 | totalPrice 73 | } 74 | } 75 | } 76 | return { 77 | Product, 78 | ShoppingCart 79 | } 80 | } 81 | 82 | module.exports = solve -------------------------------------------------------------------------------- /Practical Exams/10-September-2016/task-1/task/solution.js: -------------------------------------------------------------------------------- 1 | /* globals module */ 2 | 3 | "use strict"; 4 | 5 | function solve() { 6 | class Product { 7 | constructor(productType, name, price) { 8 | this.productType = productType; 9 | this.name = name; 10 | this.price = +price; 11 | } 12 | } 13 | 14 | class ShoppingCart { 15 | constructor() { 16 | this.products = []; 17 | } 18 | 19 | add(product) { 20 | this.products.push(product); 21 | return this; 22 | } 23 | 24 | remove(product) { 25 | let index = this.products.findIndex(pr => pr.name === product.name && pr.cost === product.cost && pr.productType === product.productType); 26 | if (index < 0) { 27 | throw new Error("No such product"); 28 | } 29 | 30 | this.products.splice(index, 1); 31 | return this; 32 | } 33 | 34 | showCost() { 35 | let cost = this.products.reduce((c, p) => c + p.price, 0); 36 | return cost; 37 | } 38 | 39 | showProductTypes() { 40 | let productTypesMap = {}; 41 | this.products.forEach(pr => { 42 | productTypesMap[pr.productType] = 1; 43 | }); 44 | 45 | return Object.keys(productTypesMap) 46 | .sort((x, y) => x.localeCompare(y)); 47 | } 48 | 49 | getInfo() { 50 | let allProducts = {}; 51 | this.products.forEach(pr => { 52 | if (!allProducts[pr.name]) { 53 | allProducts[pr.name] = { 54 | "name": pr.name, 55 | "totalPrice": 0, 56 | "quantity": 0 57 | }; 58 | } 59 | 60 | allProducts[pr.name].totalPrice += pr.price; 61 | allProducts[pr.name].quantity += 1; 62 | }); 63 | 64 | let products = Object.keys(allProducts) 65 | .sort((k1, k2) => k1.localeCompare(k2)) 66 | .map(key => allProducts[key]); 67 | 68 | let totalPrice = products.reduce((tp, pr) => tp + pr.totalPrice, 0); 69 | return { 70 | products, 71 | totalPrice 72 | }; 73 | } 74 | } 75 | return { 76 | Product, 77 | ShoppingCart 78 | }; 79 | } 80 | 81 | module.exports = solve; -------------------------------------------------------------------------------- /Practical Exams/10-September-2016/task-2/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "battlemanager", 3 | "version": "1.0.0", 4 | "description": "exam task", 5 | "main": "solution.js", 6 | "directories": { 7 | "test": "tests" 8 | }, 9 | "scripts": { 10 | "test": "mocha -R spec ./tests/tests.js", 11 | "build": "tsc --watch" 12 | }, 13 | "author": "", 14 | "license": "ISC", 15 | "dependencies": { 16 | "chai": "^3.5.0", 17 | "mocha": "^3.0.2" 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Practical Exams/23-February-2017/README.md: -------------------------------------------------------------------------------- 1 | # App stores 2 | 3 | Implement functionality for app stores and devices. Implement the given classes. 4 | 5 | ## Class descriptions 6 | 7 | ### `class App` 8 | - Constructor or init method: 9 | - takes `name`, `description`, `version` and `rating` as parameters 10 | - **throws** if any of them is not valid 11 | - Properties: 12 | - `name` - a string with length between 1 and 24 latin letters, numbers and whitespace 13 | - `description` - a string 14 | - `version` - a positive number 15 | - `rating` - a number between 1 and 10 16 | - Methods: 17 | - `release(version)` 18 | - changes the version of the app 19 | - **throws** if the new version is not above the old one 20 | - `release(options)` 21 | - `options` is an object with keys: 22 | - `version` - **mandatory** - changes the app version 23 | - **throws** if the new version is not above the old one 24 | - **throws** if the new version is invalid 25 | - **throws** if not specified 26 | - `description` - **optional** - changes the app description 27 | - **throws** if `description` is not valid 28 | - `rating` - **optional** - changes the app rating 29 | - **throws** if `rating` is not valid 30 | 31 | ### `class Store` extends `App` 32 | - The store is also an app 33 | - has all `App` properties and methods 34 | - has the `App` constructor 35 | - Properties: 36 | - `apps` - an array of uploaded apps 37 | - Methods: 38 | - `uploadApp(app)` 39 | - `app` must be a valid instance of the `App` class 40 | - if an app with the same name: 41 | - doesn't exist - creates a new app in the Store 42 | - does exist - updates the app to the newer version 43 | - updates `description` and `rating` 44 | - **throws** if the new version is not bigger than the old one 45 | - **should provide chaining** 46 | - `takedownApp(name)` 47 | - removes an app with the given `name` from the store 48 | - **throw** if an app with the given name does not exist in the store 49 | - **should provide chaining** 50 | - `search(pattern)` 51 | - performs case-insensitive search in the store 52 | - returns an array of apps containing `pattern` in their name 53 | - sort apps lexicographically by name 54 | - `listMostRecentApps(count)` 55 | - `count` is an optional parameter 56 | - defaults to 10 57 | - returns an array of the `count` most recent apps 58 | - sorted by time of upload - descending 59 | - `listMostPopularApps(count)` 60 | - `count` is an optional parameter 61 | - defaults to 10 62 | - returns an array of the `count` most popular apps 63 | - sorted by rating - descending 64 | - apps with equal rating should be sorted by time of upload - descending 65 | 66 | ### `class Device` 67 | - Constructor or init method: 68 | - takes `hostname` and an **array of pre-installed apps** (e.g. default store) 69 | - **throws** if `hostname` is not valid 70 | - **throws** if there is an invalid app 71 | - Properties: 72 | - `hostname`: a string with length between 1 and 32 symbols 73 | - `apps` - an array of installed apps 74 | - Methods: 75 | - `search(pattern)` 76 | - performs case-insensitive search in all stores installed on the device 77 | - returns an array of apps containing `pattern` in their name 78 | - sort apps lexicographically by name 79 | - return only latest versions of apps 80 | - `install(name)` 81 | - installs an app with name: `name` 82 | - find the most recent version of the app in the installed stores 83 | - does nothing if the app is already installed 84 | - **throws** if app `name` is not available in installed stores 85 | - **should provide chaining** 86 | - `uninstall(name)` 87 | - uninstalls the app with name: `name` 88 | - **throws** if no such app is installed 89 | - **should provide chaining** 90 | - `listInstalled()` 91 | - returns an array of all installed apps 92 | - sort apps lexicographically by name 93 | - `update()` 94 | - updates all installed apps to their best version across all stores installed on the device 95 | - **should provide chaining** 96 | 97 | ## Solution template 98 | 99 | ```javascript 100 | function solve() { 101 | // Your classes 102 | 103 | return { 104 | createApp(name, description, version, rating) { 105 | // returns a new App object 106 | }, 107 | createStore(name, description, version, rating) { 108 | // returns a new Store object 109 | }, 110 | createDevice(hostname, apps) { 111 | // returns a new Device object 112 | } 113 | }; 114 | } 115 | 116 | // Submit the code above this line in bgcoder.com 117 | module.exports = solve; 118 | ``` 119 | -------------------------------------------------------------------------------- /Practical Exams/23-February-2017/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "exam", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "mocha -R spec tests" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "devDependencies": { 12 | "chai": "^3.5.0", 13 | "mocha": "^3.2.0" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Sample Exams/audio-player/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "test-driven-hw-mocha", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "node_modules/mocha/bin/mocha -R spec tests" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "devDependencies": { 12 | "chai": "^3.0.0", 13 | "mocha": "^3.0.2" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Sample Exams/audio-player/tests/task-1-tests.coffee: -------------------------------------------------------------------------------- 1 | expect = require('chai').expect 2 | result = require('../tasks/task-1')() 3 | 4 | describe 'Sample exam tests', () -> 5 | describe 'Players', () -> 6 | describe 'With valid input', () -> 7 | it 'expect getPlayer to exist, to be a function and to take a single parameter', () -> 8 | expect(result.getPlayer).to.exist 9 | expect(result.getPlayer).to.be.a 'function' 10 | expect(result.getPlayer).to.have.length 1 11 | it 'expect getPlayer to return a new player instance, with provided name and generated id', () -> 12 | name = 'Rock and roll' 13 | player = result.getPlayer name 14 | expect(player).to.exist 15 | expect(player).to.be.an 'object' 16 | expect(player.name).to.equal name 17 | expect(player.id).to.exist 18 | it 'expect player.addPlaylist() to exists, to be a function, to take a single parameter and to enable chaining', () -> 19 | name = 'Rock and roll' 20 | player = result.getPlayer name 21 | playlist = result.getPlaylist name 22 | expect(player.addPlaylist).to.exist 23 | expect(player.addPlaylist).to.be.a 'function' 24 | expect(player.addPlaylist).to.have.length 1 25 | returnedPlayer = player.addPlaylist playlist 26 | expect(returnedPlayer).to.equal player 27 | it 'expect player.getPlaylistById() to return previously added playlist, when no other playlists', () -> 28 | name = 'Rock and Roll' 29 | player = result.getPlayer name 30 | playlist = result.getPlaylist name 31 | returnedPlaylist = player.addPlaylist(playlist) 32 | .getPlaylistById(playlist.id) 33 | expect(returnedPlaylist).to.equal(playlist) 34 | it 'expect player.getPlaylistById() to return previously added playlist, when there are other playlists', () -> 35 | name = 'Rock and Roll' 36 | player = result.getPlayer name 37 | playlist = result.getPlaylist name 38 | count = 5 39 | for i in [0..count] 40 | player.addPlaylist(result.getPlaylist(name + i)) 41 | player.addPlaylist(playlist) 42 | for i in [0..count] 43 | player.addPlaylist(result.getPlaylist(name + i)) 44 | expect(player.getPlaylistById playlist.id).to.equal(playlist) 45 | it 'expect player.getPlaylistById() with id, not contianed in the player to return null, when there are other playlists and when there are no playlists at all', () -> 46 | name = 'Rock and Roll' 47 | player = result.getPlayer name 48 | 49 | expect(player.getPlaylist(2)).to.be.null 50 | count = 5 51 | ids = {} 52 | for i in [0..count] 53 | playlist = result.getPlaylist(name + i) 54 | player.addPlaylist(playlist) 55 | ids[playlist.id] = true 56 | invalidID = (Math.random() * 100000000) | 0 57 | while ids[invalidID] 58 | invalidID = (Math.random() * 100000000) | 0 59 | expect(player.getPlaylist(invalidID)).to.be.null 60 | it 'expect player.removePlaylist() to remove the playlist, when id is provided', -> 61 | name = 'Rock and Roll' 62 | player = result.getPlayer name 63 | playlist = result.getPlaylist name 64 | player.addPlaylist(playlist) 65 | .removePlaylist(playlist.id) 66 | expect(player.getPlaylistById(playlist.id)).to.be.null 67 | 68 | for i in [0..5] 69 | player.addPlaylist(name + i) 70 | -------------------------------------------------------------------------------- /Sample Exams/audio-player/tests/task-1-tests.js: -------------------------------------------------------------------------------- 1 | // Generated by CoffeeScript 1.9.3 2 | var expect, result; 3 | 4 | expect = require('chai').expect; 5 | 6 | result = require('../tasks/task-1')(); 7 | 8 | describe('Sample exam tests', function() { 9 | return describe('Players', function() { 10 | return describe('With valid input', function() { 11 | it('expect getPlayer to exist, to be a function and to take a single parameter', function() { 12 | expect(result.getPlayer).to.exist; 13 | expect(result.getPlayer).to.be.a('function'); 14 | return expect(result.getPlayer).to.have.length(1); 15 | }); 16 | it('expect getPlayer to return a new player instance, with provided name and generated id', function() { 17 | var name, player; 18 | name = 'Rock and roll'; 19 | player = result.getPlayer(name); 20 | expect(player).to.exist; 21 | expect(player).to.be.an('object'); 22 | expect(player.name).to.equal(name); 23 | return expect(player.id).to.exist; 24 | }); 25 | it('expect player.addPlaylist() to exists, to be a function, to take a single parameter and to enable chaining', function() { 26 | var name, player, playlist, returnedPlayer; 27 | name = 'Rock and roll'; 28 | player = result.getPlayer(name); 29 | playlist = result.getPlaylist(name); 30 | expect(player.addPlaylist).to.exist; 31 | expect(player.addPlaylist).to.be.a('function'); 32 | expect(player.addPlaylist).to.have.length(1); 33 | returnedPlayer = player.addPlaylist(playlist); 34 | return expect(returnedPlayer).to.equal(player); 35 | }); 36 | it('expect player.getPlaylistById() to return previously added playlist, when no other playlists', function() { 37 | var name, player, playlist, returnedPlaylist; 38 | name = 'Rock and Roll'; 39 | player = result.getPlayer(name); 40 | playlist = result.getPlaylist(name); 41 | returnedPlaylist = player.addPlaylist(playlist).getPlaylistById(playlist.id); 42 | return expect(returnedPlaylist).to.equal(playlist); 43 | }); 44 | it('expect player.getPlaylistById() to return previously added playlist, when there are other playlists', function() { 45 | var count, i, j, k, name, player, playlist, ref, ref1; 46 | name = 'Rock and Roll'; 47 | player = result.getPlayer(name); 48 | playlist = result.getPlaylist(name); 49 | count = 5; 50 | for (i = j = 0, ref = count; 0 <= ref ? j <= ref : j >= ref; i = 0 <= ref ? ++j : --j) { 51 | player.addPlaylist(result.getPlaylist(name + i)); 52 | } 53 | player.addPlaylist(playlist); 54 | for (i = k = 0, ref1 = count; 0 <= ref1 ? k <= ref1 : k >= ref1; i = 0 <= ref1 ? ++k : --k) { 55 | player.addPlaylist(result.getPlaylist(name + i)); 56 | } 57 | return expect(player.getPlaylistById(playlist.id)).to.equal(playlist); 58 | }); 59 | it('expect player.getPlaylistById() with id, not contained in the player to return null, when there are other playlists and when there are no playlists at all', function() { 60 | var count, i, ids, invalidID, j, name, player, playlist, ref; 61 | name = 'Rock and Roll'; 62 | player = result.getPlayer(name); 63 | expect(player.getPlaylistById(2)).to.be["null"]; 64 | count = 5; 65 | ids = {}; 66 | for (i = j = 0, ref = count; 0 <= ref ? j <= ref : j >= ref; i = 0 <= ref ? ++j : --j) { 67 | playlist = result.getPlaylist(name + i); 68 | player.addPlaylist(playlist); 69 | ids[playlist.id] = true; 70 | } 71 | invalidID = (Math.random() * 100000000) | 0; 72 | while (ids[invalidID]) { 73 | invalidID = (Math.random() * 100000000) | 0; 74 | } 75 | return expect(player.getPlaylistById(invalidID)).to.be["null"]; 76 | }); 77 | return it('expect player.removePlaylist() to remove the playlist, when id is provided', function() { 78 | var i, j, name, player, playlist, results; 79 | name = 'Rock and Roll'; 80 | player = result.getPlayer(name); 81 | playlist = result.getPlaylist(name); 82 | player.addPlaylist(playlist).removePlaylist(playlist.id); 83 | expect(player.getPlaylistById(playlist.id)).to.be["null"]; 84 | results = []; 85 | for (i = j = 0; j <= 5; i = ++j) { 86 | results.push(player.addPlaylist(result.getPlaylist(name + i))); 87 | } 88 | return results; 89 | }); 90 | }); 91 | }); 92 | }); 93 | 94 | //# sourceMappingURL=task-1-tests.js.map 95 | -------------------------------------------------------------------------------- /Sample Exams/audio-player/tests/task-1-tests.js.map: -------------------------------------------------------------------------------- 1 | { 2 | "version": 3, 3 | "file": "task-1-tests.js", 4 | "sourceRoot": "", 5 | "sources": [ 6 | "task-1-tests.coffee" 7 | ], 8 | "names": [], 9 | "mappings": ";AAAA,IAAA;;AAAA,MAAA,GAAS,OAAA,CAAQ,MAAR,CAAe,CAAC;;AACzB,MAAA,GAAS,OAAA,CAAQ,iBAAR,CAAA,CAAA;;AAET,QAAA,CAAS,mBAAT,EAA8B,SAAA;SAC1B,QAAA,CAAS,SAAT,EAAoB,SAAA;WAChB,QAAA,CAAS,kBAAT,EAA6B,SAAA;MACzB,EAAA,CAAG,4EAAH,EAAiF,SAAA;QAC7E,MAAA,CAAO,MAAM,CAAC,SAAd,CAAwB,CAAC,EAAE,CAAC;QAC5B,MAAA,CAAO,MAAM,CAAC,SAAd,CAAwB,CAAC,EAAE,CAAC,EAAE,CAAC,CAA/B,CAAiC,UAAjC;eACA,MAAA,CAAO,MAAM,CAAC,SAAd,CAAwB,CAAC,EAAE,CAAC,IAAI,CAAC,MAAjC,CAAwC,CAAxC;MAH6E,CAAjF;MAIA,EAAA,CAAG,uFAAH,EAA4F,SAAA;AACxF,YAAA;QAAA,IAAA,GAAO;QACP,MAAA,GAAS,MAAM,CAAC,SAAP,CAAiB,IAAjB;QACT,MAAA,CAAO,MAAP,CAAc,CAAC,EAAE,CAAC;QAClB,MAAA,CAAO,MAAP,CAAc,CAAC,EAAE,CAAC,EAAE,CAAC,EAArB,CAAwB,QAAxB;QACA,MAAA,CAAO,MAAM,CAAC,IAAd,CAAmB,CAAC,EAAE,CAAC,KAAvB,CAA6B,IAA7B;eACA,MAAA,CAAO,MAAM,CAAC,EAAd,CAAiB,CAAC,EAAE,CAAC;MANmE,CAA5F;MAOA,EAAA,CAAG,4GAAH,EAAiH,SAAA;AAC7G,YAAA;QAAA,IAAA,GAAO;QACP,MAAA,GAAS,MAAM,CAAC,SAAP,CAAiB,IAAjB;QACT,QAAA,GAAW,MAAM,CAAC,WAAP,CAAmB,IAAnB;QACX,MAAA,CAAO,MAAM,CAAC,WAAd,CAA0B,CAAC,EAAE,CAAC;QAC9B,MAAA,CAAO,MAAM,CAAC,WAAd,CAA0B,CAAC,EAAE,CAAC,EAAE,CAAC,CAAjC,CAAmC,UAAnC;QACA,MAAA,CAAO,MAAM,CAAC,WAAd,CAA0B,CAAC,EAAE,CAAC,IAAI,CAAC,MAAnC,CAA0C,CAA1C;QACA,cAAA,GAAiB,MAAM,CAAC,WAAP,CAAmB,QAAnB;eACjB,MAAA,CAAO,cAAP,CAAsB,CAAC,EAAE,CAAC,KAA1B,CAAgC,MAAhC;MAR6G,CAAjH;MASA,EAAA,CAAG,8FAAH,EAAmG,SAAA;AAC/F,YAAA;QAAA,IAAA,GAAO;QACP,MAAA,GAAS,MAAM,CAAC,SAAP,CAAiB,IAAjB;QACT,QAAA,GAAW,MAAM,CAAC,WAAP,CAAmB,IAAnB;QACX,gBAAA,GAAmB,MAAM,CAAC,WAAP,CAAmB,QAAnB,CACf,CAAC,eADc,CACE,QAAQ,CAAC,EADX;eAEnB,MAAA,CAAO,gBAAP,CAAwB,CAAC,EAAE,CAAC,KAA5B,CAAkC,QAAlC;MAN+F,CAAnG;MAOA,EAAA,CAAG,qGAAH,EAA0G,SAAA;AACtG,YAAA;QAAA,IAAA,GAAO;QACP,MAAA,GAAS,MAAM,CAAC,SAAP,CAAiB,IAAjB;QACT,QAAA,GAAW,MAAM,CAAC,WAAP,CAAmB,IAAnB;QACX,KAAA,GAAQ;AACR,aAAS,gFAAT;UACI,MAAM,CAAC,WAAP,CAAmB,MAAM,CAAC,WAAP,CAAmB,IAAA,GAAO,CAA1B,CAAnB;AADJ;QAEA,MAAM,CAAC,WAAP,CAAmB,QAAnB;AACA,aAAS,qFAAT;UACI,MAAM,CAAC,WAAP,CAAmB,MAAM,CAAC,WAAP,CAAmB,IAAA,GAAO,CAA1B,CAAnB;AADJ;eAEA,MAAA,CAAO,MAAM,CAAC,eAAP,CAAuB,QAAQ,CAAC,EAAhC,CAAP,CAA0C,CAAC,EAAE,CAAC,KAA9C,CAAoD,QAApD;MAVsG,CAA1G;MAWA,EAAA,CAAG,4JAAH,EAAiK,SAAA;AAC7J,YAAA;QAAA,IAAA,GAAO;QACP,MAAA,GAAS,MAAM,CAAC,SAAP,CAAiB,IAAjB;QAET,MAAA,CAAO,MAAM,CAAC,WAAP,CAAmB,CAAnB,CAAP,CAA6B,CAAC,EAAE,CAAC,EAAE,CAAC,MAAD;QACnC,KAAA,GAAQ;QACR,GAAA,GAAM;AACN,aAAS,gFAAT;UACI,QAAA,GAAW,MAAM,CAAC,WAAP,CAAmB,IAAA,GAAO,CAA1B;UACX,MAAM,CAAC,WAAP,CAAmB,QAAnB;UACA,GAAI,CAAA,QAAQ,CAAC,EAAT,CAAJ,GAAmB;AAHvB;QAIA,SAAA,GAAY,CAAC,IAAI,CAAC,MAAL,CAAA,CAAA,GAAgB,SAAjB,CAAA,GAA8B;AAC1C,eAAM,GAAI,CAAA,SAAA,CAAV;UACI,SAAA,GAAY,CAAC,IAAI,CAAC,MAAL,CAAA,CAAA,GAAgB,SAAjB,CAAA,GAA8B;QAD9C;eAEA,MAAA,CAAO,MAAM,CAAC,WAAP,CAAmB,SAAnB,CAAP,CAAqC,CAAC,EAAE,CAAC,EAAE,CAAC,MAAD;MAdkH,CAAjK;aAeA,EAAA,CAAG,4EAAH,EAAiF,SAAA;AAC7E,YAAA;QAAA,IAAA,GAAO;QACP,MAAA,GAAS,MAAM,CAAC,SAAP,CAAiB,IAAjB;QACT,QAAA,GAAW,MAAM,CAAC,WAAP,CAAmB,IAAnB;QACX,MAAM,CAAC,WAAP,CAAmB,QAAnB,CACI,CAAC,cADL,CACoB,QAAQ,CAAC,EAD7B;QAEA,MAAA,CAAO,MAAM,CAAC,eAAP,CAAuB,QAAQ,CAAC,EAAhC,CAAP,CAA2C,CAAC,EAAE,CAAC,EAAE,CAAC,MAAD;AAEjD;aAAS,0BAAT;uBACI,MAAM,CAAC,WAAP,CAAmB,IAAA,GAAO,CAA1B;AADJ;;MAR6E,CAAjF;IAtDyB,CAA7B;EADgB,CAApB;AAD0B,CAA9B" 10 | } -------------------------------------------------------------------------------- /Topics/00. Course-Introduction/imgs/pic00.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/00. Course-Introduction/imgs/pic00.png -------------------------------------------------------------------------------- /Topics/00. Course-Introduction/imgs/pic01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/00. Course-Introduction/imgs/pic01.png -------------------------------------------------------------------------------- /Topics/00. Course-Introduction/imgs/pic02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/00. Course-Introduction/imgs/pic02.png -------------------------------------------------------------------------------- /Topics/00. Course-Introduction/imgs/pic03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/00. Course-Introduction/imgs/pic03.png -------------------------------------------------------------------------------- /Topics/00. Course-Introduction/imgs/pic04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/00. Course-Introduction/imgs/pic04.png -------------------------------------------------------------------------------- /Topics/00. Course-Introduction/imgs/pic05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/00. Course-Introduction/imgs/pic05.png -------------------------------------------------------------------------------- /Topics/00. Course-Introduction/imgs/pic06.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/00. Course-Introduction/imgs/pic06.png -------------------------------------------------------------------------------- /Topics/00. Course-Introduction/imgs/pic07.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/00. Course-Introduction/imgs/pic07.png -------------------------------------------------------------------------------- /Topics/00. Course-Introduction/imgs/pic08.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/00. Course-Introduction/imgs/pic08.png -------------------------------------------------------------------------------- /Topics/00. Course-Introduction/imgs/pic09.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/00. Course-Introduction/imgs/pic09.png -------------------------------------------------------------------------------- /Topics/00. Course-Introduction/imgs/pic10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/00. Course-Introduction/imgs/pic10.png -------------------------------------------------------------------------------- /Topics/00. Course-Introduction/imgs/pic11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/00. Course-Introduction/imgs/pic11.png -------------------------------------------------------------------------------- /Topics/00. Course-Introduction/imgs/pic12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/00. Course-Introduction/imgs/pic12.png -------------------------------------------------------------------------------- /Topics/00. Course-Introduction/imgs/pic13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/00. Course-Introduction/imgs/pic13.png -------------------------------------------------------------------------------- /Topics/00. Course-Introduction/imgs/pic14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/00. Course-Introduction/imgs/pic14.png -------------------------------------------------------------------------------- /Topics/00. Course-Introduction/imgs/pic15.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/00. Course-Introduction/imgs/pic15.png -------------------------------------------------------------------------------- /Topics/00. Course-Introduction/imgs/pic16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/00. Course-Introduction/imgs/pic16.png -------------------------------------------------------------------------------- /Topics/00. Course-Introduction/imgs/pic17.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/00. Course-Introduction/imgs/pic17.png -------------------------------------------------------------------------------- /Topics/00. Course-Introduction/imgs/pic18.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/00. Course-Introduction/imgs/pic18.png -------------------------------------------------------------------------------- /Topics/00. Course-Introduction/imgs/pic19.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/00. Course-Introduction/imgs/pic19.png -------------------------------------------------------------------------------- /Topics/00. Course-Introduction/imgs/pic20.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/00. Course-Introduction/imgs/pic20.png -------------------------------------------------------------------------------- /Topics/00. Course-Introduction/imgs/pic21.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/00. Course-Introduction/imgs/pic21.png -------------------------------------------------------------------------------- /Topics/00. Course-Introduction/imgs/pic22.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/00. Course-Introduction/imgs/pic22.png -------------------------------------------------------------------------------- /Topics/00. Course-Introduction/imgs/pic23.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/00. Course-Introduction/imgs/pic23.png -------------------------------------------------------------------------------- /Topics/00. Course-Introduction/imgs/pic24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/00. Course-Introduction/imgs/pic24.png -------------------------------------------------------------------------------- /Topics/00. Course-Introduction/imgs/pic25.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/00. Course-Introduction/imgs/pic25.png -------------------------------------------------------------------------------- /Topics/00. Course-Introduction/imgs/pic26.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/00. Course-Introduction/imgs/pic26.png -------------------------------------------------------------------------------- /Topics/00. Course-Introduction/imgs/pic27.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/00. Course-Introduction/imgs/pic27.png -------------------------------------------------------------------------------- /Topics/00. Course-Introduction/imgs/pic28.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/00. Course-Introduction/imgs/pic28.png -------------------------------------------------------------------------------- /Topics/00. Course-Introduction/imgs/pic29.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/00. Course-Introduction/imgs/pic29.png -------------------------------------------------------------------------------- /Topics/00. Course-Introduction/imgs/pic30.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/00. Course-Introduction/imgs/pic30.png -------------------------------------------------------------------------------- /Topics/00. Course-Introduction/imgs/pic31.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/00. Course-Introduction/imgs/pic31.png -------------------------------------------------------------------------------- /Topics/00. Course-Introduction/imgs/pic32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/00. Course-Introduction/imgs/pic32.png -------------------------------------------------------------------------------- /Topics/00. Course-Introduction/imgs/pic33.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/00. Course-Introduction/imgs/pic33.png -------------------------------------------------------------------------------- /Topics/00. Course-Introduction/imgs/pic34.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/00. Course-Introduction/imgs/pic34.png -------------------------------------------------------------------------------- /Topics/00. Course-Introduction/imgs/pic37.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/00. Course-Introduction/imgs/pic37.png -------------------------------------------------------------------------------- /Topics/00. Course-Introduction/imgs/pic38.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/00. Course-Introduction/imgs/pic38.png -------------------------------------------------------------------------------- /Topics/00. Course-Introduction/imgs/pic39.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/00. Course-Introduction/imgs/pic39.png -------------------------------------------------------------------------------- /Topics/00. Course-Introduction/imgs/pic40.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/00. Course-Introduction/imgs/pic40.png -------------------------------------------------------------------------------- /Topics/00. Course-Introduction/imgs/pic41.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/00. Course-Introduction/imgs/pic41.png -------------------------------------------------------------------------------- /Topics/00. Course-Introduction/imgs/pic42.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/00. Course-Introduction/imgs/pic42.png -------------------------------------------------------------------------------- /Topics/00. Course-Introduction/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Course Introduction 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 26 | 27 | 28 | 29 |
30 |
31 |
32 | 33 | 34 | 35 | 36 | 37 | 38 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /Topics/01. Functions-and-Function-Expressions/demos/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "name": "Launch", 6 | "type": "node", 7 | "request": "launch", 8 | "program": "${workspaceRoot}/app.js", 9 | "stopOnEntry": false, 10 | "args": [], 11 | "cwd": "${workspaceRoot}", 12 | "preLaunchTask": null, 13 | "runtimeExecutable": null, 14 | "runtimeArgs": [ 15 | "--nolazy" 16 | ], 17 | "env": { 18 | "NODE_ENV": "development" 19 | }, 20 | "externalConsole": false, 21 | "sourceMaps": false, 22 | "outDir": null 23 | }, 24 | { 25 | "name": "Attach", 26 | "type": "node", 27 | "request": "attach", 28 | "port": 5858, 29 | "address": "localhost", 30 | "restart": false, 31 | "sourceMaps": false, 32 | "outDir": null, 33 | "localRoot": "${workspaceRoot}", 34 | "remoteRoot": null 35 | }, 36 | { 37 | "name": "Attach to Process", 38 | "type": "node", 39 | "request": "attach", 40 | "processId": "${command.PickProcess}", 41 | "port": 5858, 42 | "sourceMaps": false, 43 | "outDir": null 44 | } 45 | ] 46 | } -------------------------------------------------------------------------------- /Topics/01. Functions-and-Function-Expressions/demos/01. functions/functions.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Function Expressions: Functions demo 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Topics/01. Functions-and-Function-Expressions/demos/01. functions/functions.js: -------------------------------------------------------------------------------- 1 | /* globals console*/ 2 | 3 | function sum(...items) { 4 | if (Array.isArray(items[0])) { 5 | items = items[0]; 6 | } 7 | 8 | let itemsSum = 0; 9 | if (typeof items[0] !== "number") { 10 | itemsSum = ""; 11 | } 12 | 13 | for (let item of items) { 14 | itemsSum += item; 15 | } 16 | 17 | return itemsSum; 18 | } 19 | 20 | console.log(sum([1, 2, 3, 4, 5, 6])); 21 | console.log(sum(["Peter", " ", "Ivanov"])); -------------------------------------------------------------------------------- /Topics/01. Functions-and-Function-Expressions/demos/02. function-object/function-object.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Function Expressions: Function Object 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Topics/01. Functions-and-Function-Expressions/demos/02. function-object/function-object.js: -------------------------------------------------------------------------------- 1 | /* globals console */ 2 | 3 | function numberToDigitNames(n) { 4 | let numberString = n.toString(); 5 | let digitNames = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"]; 6 | let numberWithDigitNames = []; 7 | 8 | for (let digit of numberString) { 9 | numberWithDigitNames.push(digitNames[digit]); 10 | } 11 | 12 | return numberWithDigitNames.join("-"); 13 | } 14 | 15 | console.log(`The function ${numberToDigitNames.name}() takes ${numberToDigitNames.length} parameters"`); 16 | 17 | let numbers = [1, 12, 123, 1234, 12345, 123456, 1234567, 12345678, 123456789, 1234567890]; 18 | 19 | let numbersWithDigitNames = numbers.map(numberToDigitNames); 20 | 21 | console.log(numbersWithDigitNames.join("\n")); -------------------------------------------------------------------------------- /Topics/01. Functions-and-Function-Expressions/demos/03. function-declarations/function-declarations.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Function Expressions: function declarations demo 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /Topics/01. Functions-and-Function-Expressions/demos/03. function-declarations/function-declarations.js: -------------------------------------------------------------------------------- 1 | /* globals console */ 2 | 3 | log("Text for message"); 4 | 5 | function log(message) { 6 | var line = "-".repeat(message.length); 7 | console.log(line); 8 | //used before defined 9 | console.log(`[${getFormattedTime()}]: ${message}`); 10 | console.log(line); 11 | } 12 | 13 | function getFormattedTime(date) { 14 | date = date || new Date(); 15 | 16 | let seconds = date.getSeconds(); 17 | let minutes = date.getMinutes(); 18 | let hours = date.getHours(); 19 | 20 | let hoursString = (hours > 9 ? "" : "0") + hours.toString(); 21 | let minutesString = (minutes > 9 ? "" : "0") + minutes.toString(); 22 | let secondsString = (seconds > 9 ? "" : "0") + seconds.toString(); 23 | return `${hoursString}:${minutesString}:${secondsString}`; 24 | } -------------------------------------------------------------------------------- /Topics/01. Functions-and-Function-Expressions/demos/04. function-expressions/function-expressions.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Function Expressions: Demo 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /Topics/01. Functions-and-Function-Expressions/demos/04. function-expressions/function-expressions.js: -------------------------------------------------------------------------------- 1 | /* globals console */ 2 | 3 | var print = function(message) { 4 | let doc = this.document; 5 | if (doc && doc.body) { 6 | doc.body.innerHTML += 7 | `
${message}
`; 8 | } else { 9 | console.log(message); 10 | } 11 | }; 12 | 13 | print(123); 14 | 15 | let f3 = function() { 16 | print("This is f3"); 17 | }; 18 | 19 | let f2 = function() { 20 | f3(); 21 | print("This is f2"); 22 | }; 23 | 24 | let f1 = function() { 25 | f2(); 26 | print("This is f1"); 27 | }; 28 | 29 | f1(); -------------------------------------------------------------------------------- /Topics/01. Functions-and-Function-Expressions/demos/05. function-constructor/function-constructor.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Function expressions: Function constructors demo 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /Topics/01. Functions-and-Function-Expressions/demos/05. function-constructor/function-constructor.js: -------------------------------------------------------------------------------- 1 | /* globals console */ 2 | 3 | let maxParams = "items"; 4 | let maxBody = ` 5 | let maxItem = items[0]; 6 | for (let item of items) { 7 | maxItem = Math.max(item, maxItem); 8 | } 9 | return maxItem; 10 | `; 11 | 12 | let maxFunc = new Function(maxParams, maxBody); 13 | console.log(maxFunc([1, 2, 3, 4])); -------------------------------------------------------------------------------- /Topics/01. Functions-and-Function-Expressions/demos/06. expressions-vs-declarations/expressions-vs-declarations.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Function expressions: Expressions vs. Declarations demos 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /Topics/01. Functions-and-Function-Expressions/demos/06. expressions-vs-declarations/expressions-vs-declarations.js: -------------------------------------------------------------------------------- 1 | if (true) { 2 | //remove the comment to fix the bug 3 | // var print = 4 | function print(msg) { 5 | console.log('--from if'); 6 | console.log(msg); 7 | } 8 | } else { 9 | //remove the comment to fix the bug 10 | function print(msg) { 11 | console.log('--from else'); 12 | console.log(msg); 13 | } 14 | } 15 | print('Test'); -------------------------------------------------------------------------------- /Topics/01. Functions-and-Function-Expressions/demos/07. function-methods/function-methods.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Function expressions: Function methods demo 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /Topics/01. Functions-and-Function-Expressions/demos/07. function-methods/function-methods.js: -------------------------------------------------------------------------------- 1 | /* globals console */ 2 | 3 | function toArray(obj) { 4 | let arr; 5 | if (obj.length) { 6 | arr = Array.from(obj); 7 | } else { 8 | arr = []; 9 | for (let prop in obj) { 10 | if (typeof obj[prop] !== "function") { 11 | arr.push({ 12 | prop: prop, 13 | value: obj[prop] 14 | }); 15 | } 16 | } 17 | } 18 | return arr; 19 | } 20 | 21 | function passArguments() { 22 | console.log(toArray(arguments)); 23 | } 24 | 25 | let obj = { 26 | fistname: "Doncho", 27 | lastname: "Minkov", 28 | specialities: ["JavaScript", "Web", "Android", "iOS", "Window Phone"] 29 | }; 30 | 31 | console.log("Arguments collection:"); 32 | passArguments(1, 2, 3, 4, 5, 6, 7); 33 | console.log("Object:"); 34 | console.log(toArray(obj)); -------------------------------------------------------------------------------- /Topics/01. Functions-and-Function-Expressions/demos/08. recursion-factorial/recursion-factorial.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Function expressions: Recursion demo 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /Topics/01. Functions-and-Function-Expressions/demos/08. recursion-factorial/recursion-factorial.js: -------------------------------------------------------------------------------- 1 | /* globals console */ 2 | 3 | function factorial(n) { 4 | if (n === 0) { 5 | return 1; 6 | } 7 | return n * factorial(n - 1); 8 | } 9 | 10 | console.log(factorial(5)); 11 | console.log(factorial(12)); -------------------------------------------------------------------------------- /Topics/01. Functions-and-Function-Expressions/demos/09. recursion-traversing-dom/recursion-traversing-dom.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Function expressions: Traversing the DOM demo 6 | 7 | 8 |

This is a complex demo of recursion in JavaScript

9 | 10 | 11 | -------------------------------------------------------------------------------- /Topics/01. Functions-and-Function-Expressions/demos/09. recursion-traversing-dom/recursion-traversing-dom.js: -------------------------------------------------------------------------------- 1 | /* globals console, document */ 2 | 3 | function traverse(element) { 4 | function traverseElement(node, spacing) { 5 | if (node.nodeType !== 1) { 6 | return; 7 | } 8 | 9 | spacing = spacing || " "; 10 | 11 | console.log(spacing + node.nodeName); 12 | [...node.childNodes].forEach(child => traverseElement(child, spacing + "--")); 13 | 14 | console.log(spacing + "/" + node.nodeName); 15 | } 16 | 17 | traverseElement(element, ""); 18 | } 19 | 20 | traverse(document.documentElement); -------------------------------------------------------------------------------- /Topics/01. Functions-and-Function-Expressions/demos/10. buggy-recursin-expressions/buggy-recursin-expressions.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Function expressions: Buggy recursion with expressions demo 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /Topics/01. Functions-and-Function-Expressions/demos/10. buggy-recursin-expressions/buggy-recursin-expressions.js: -------------------------------------------------------------------------------- 1 | /* globals console */ 2 | 3 | let factorial = function(n) { 4 | if (n === 0) { 5 | return 1; 6 | } 7 | return n * factorial(n - 1); 8 | }; 9 | 10 | console.log(factorial(5)); 11 | 12 | let fact = factorial; 13 | console.log(fact(5)); 14 | 15 | factorial = function() { 16 | return "NOT FACTORIAL"; 17 | }; 18 | 19 | console.log(fact(5)); -------------------------------------------------------------------------------- /Topics/01. Functions-and-Function-Expressions/demos/11. recursiоn-expressions/recursiоn-expressions.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Function expressions: Working recursion with expressions demo 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /Topics/01. Functions-and-Function-Expressions/demos/11. recursiоn-expressions/recursiоn-expressions.js: -------------------------------------------------------------------------------- 1 | /* globals console */ 2 | 3 | let factorial = function factorial(n) { 4 | if (n === 0) { 5 | return 1; 6 | } 7 | return n * factorial(n - 1); 8 | }; 9 | 10 | console.log(factorial(5)); 11 | 12 | let fact = factorial; 13 | console.log(fact(5)); 14 | 15 | factorial = function() { 16 | return "NOT FACTORIAL"; 17 | }; 18 | 19 | console.log(fact(5)); -------------------------------------------------------------------------------- /Topics/01. Functions-and-Function-Expressions/demos/14. nested-functions/nested-functions.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Function expressions: Nested functions demo 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /Topics/01. Functions-and-Function-Expressions/demos/14. nested-functions/nested-functions.js: -------------------------------------------------------------------------------- 1 | /* globals console document*/ 2 | 3 | function getPrint(type) { 4 | function printInDom(text) { 5 | document.body.innerHTML += "
" + text + "
"; 6 | } 7 | 8 | function printInConsole(text) { 9 | console.log(text); 10 | } 11 | 12 | if (type === "dom") { 13 | return printInDom; 14 | } else if (type === "server") { 15 | return printInConsole; 16 | } 17 | return null; 18 | } 19 | 20 | let printType = (this.document) ? "dom" : "server"; 21 | let print = getPrint(printType); 22 | print("Message"); -------------------------------------------------------------------------------- /Topics/01. Functions-and-Function-Expressions/demos/15. immediately-invoked-function-expressions/immediately-invoked-function-expressions.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Functions: Immediately-invoked Function Expressions demo 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /Topics/01. Functions-and-Function-Expressions/demos/15. immediately-invoked-function-expressions/immediately-invoked-function-expressions.js: -------------------------------------------------------------------------------- 1 | /* globals console */ 2 | 3 | (function() { 4 | console.log("Invoked"); 5 | }()); -------------------------------------------------------------------------------- /Topics/01. Functions-and-Function-Expressions/demos/18. closures-usage-jquery-prototype/closures-usage-jquery-prototype.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Functions: jQuery with Closures 6 | 7 | 8 |
9 | text 10 |
11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Topics/01. Functions-and-Function-Expressions/demos/18. closures-usage-jquery-prototype/closures-usage-jquery-prototype.js: -------------------------------------------------------------------------------- 1 | // (function ($) { 2 | // var $root = $('#root'); 3 | 4 | // console.log($root.html()); 5 | // //Error! $ is not jQuery here (Prototype.js is loaded last) 6 | // }(jQuery)); 7 | 8 | // (function ($) { 9 | var $root = $("root"); 10 | 11 | console.log($root.innerHTML); 12 | // }(Prototype)); -------------------------------------------------------------------------------- /Topics/01. Functions-and-Function-Expressions/homework/README.md: -------------------------------------------------------------------------------- 1 | Functions and Function Expressions 2 | ================================== 3 | 4 | ### Task 1. 5 | * Write a function that sums an array of numbers: 6 | * Numbers must be always of type `Number` 7 | * Returns `null` if the array is empty 8 | * Throws Error if the parameter is not passed (undefined) 9 | * Throws if any of the elements is not convertible to `Number` 10 | 11 | ### Task 2. 12 | * Write a function that finds all the prime numbers in a range 13 | * It should return the prime numbers in an array 14 | * It must throw an Error if any of the range params is not convertible to `Number` 15 | * It must throw an Error if any of the range params is missing 16 | -------------------------------------------------------------------------------- /Topics/01. Functions-and-Function-Expressions/homework/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "test-driven-hw-mocha", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "mocha -R spec tests" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "devDependencies": { 12 | "chai": "^3.5.0", 13 | "mocha": "^3.2.0" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Topics/01. Functions-and-Function-Expressions/homework/tasks/task-1.js: -------------------------------------------------------------------------------- 1 | /* Task Description */ 2 | /* 3 | Write a function that sums an array of numbers: 4 | numbers must be always of type Number 5 | returns `null` if the array is empty 6 | throws Error if the parameter is not passed (undefined) 7 | throws if any of the elements is not convertible to Number 8 | 9 | */ 10 | 11 | function solve() { 12 | return function sum() { 13 | } 14 | } 15 | 16 | module.exports = solve; 17 | -------------------------------------------------------------------------------- /Topics/01. Functions-and-Function-Expressions/homework/tasks/task-2.js: -------------------------------------------------------------------------------- 1 | /* Task description */ 2 | /* 3 | Write a function that finds all the prime numbers in a range 4 | 1) it should return the prime numbers in an array 5 | 2) it must throw an Error if any on the range params is not convertible to `Number` 6 | 3) it must throw an Error if any of the range params is missing 7 | */ 8 | 9 | function solve() { 10 | return function findPrimes() { 11 | } 12 | } 13 | 14 | module.exports = solve; 15 | -------------------------------------------------------------------------------- /Topics/01. Functions-and-Function-Expressions/homework/tests/tests-task-1.js: -------------------------------------------------------------------------------- 1 | /* globals describe, it */ 2 | var solve = require('../tasks/task-1')(); 3 | var expect = require('chai').expect; 4 | 5 | describe('Tests for "Task 1"', function () { 6 | it('expect solve([1, 2, 3]) to be equal to 6', function () { 7 | expect(solve([1, 2, 3])).to.equal(6); 8 | }); 9 | 10 | it('expect solve([]) to return null', function () { 11 | expect(solve([])).to.be.null; 12 | }); 13 | 14 | it('expect solve() to throw Error', function () { 15 | function test() { 16 | solve(); 17 | } 18 | expect(test).to.throw(); 19 | }); 20 | 21 | it('expect solve(["1", "2"]) to be equal to 3', function () { 22 | expect(solve(['1', '2'])).to.eql(3); 23 | }); 24 | 25 | it('expect solve(["1", "John"]) to throw Error', function () { 26 | function test() { 27 | solve(['1', 'John']); 28 | } 29 | expect(test).to.throw(); 30 | }); 31 | }); 32 | -------------------------------------------------------------------------------- /Topics/01. Functions-and-Function-Expressions/homework/tests/tests-task-2.js: -------------------------------------------------------------------------------- 1 | /* globals describe, it */ 2 | 3 | 4 | var solve = require('../tasks/task-2')(); 5 | 6 | var expect = require('chai').expect; 7 | describe('Tests for "Task 2"', function () { 8 | it('expect solve(1, 5) to be equal to [2, 3, 5]', function () { 9 | expect(solve(1, 5)).to.eql([2, 3, 5]); 10 | }); 11 | 12 | it('expect solve(0, 5) to be equal to [2, 3, 5]', function(){ 13 | expect(solve(0, 5)).to.eql([2, 3, 5]); 14 | }); 15 | 16 | it('expect solve("1", "5") to be equal to [2, 3, 5]', function () { 17 | expect(solve('1', '5')).to.eql([2, 3, 5]); 18 | }); 19 | 20 | it('expect solve() to throw error', function () { 21 | function test() { 22 | solve(); 23 | } 24 | expect(test).to.throw(); 25 | }); 26 | 27 | it('expect solve(1) to throw error', function () { 28 | function test() { 29 | solve(1); 30 | } 31 | expect(test).to.throw(); 32 | }); 33 | 34 | it('expect solve(258, 262) to be equal to [](empty array)', function () { 35 | expect(solve(258, 262)).to.be.empty; 36 | }); 37 | }); 38 | -------------------------------------------------------------------------------- /Topics/01. Functions-and-Function-Expressions/imgs/pic00.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/01. Functions-and-Function-Expressions/imgs/pic00.png -------------------------------------------------------------------------------- /Topics/01. Functions-and-Function-Expressions/imgs/pic01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/01. Functions-and-Function-Expressions/imgs/pic01.png -------------------------------------------------------------------------------- /Topics/01. Functions-and-Function-Expressions/imgs/pic02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/01. Functions-and-Function-Expressions/imgs/pic02.png -------------------------------------------------------------------------------- /Topics/01. Functions-and-Function-Expressions/imgs/pic03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/01. Functions-and-Function-Expressions/imgs/pic03.png -------------------------------------------------------------------------------- /Topics/01. Functions-and-Function-Expressions/imgs/pic04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/01. Functions-and-Function-Expressions/imgs/pic04.png -------------------------------------------------------------------------------- /Topics/01. Functions-and-Function-Expressions/imgs/pic05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/01. Functions-and-Function-Expressions/imgs/pic05.png -------------------------------------------------------------------------------- /Topics/01. Functions-and-Function-Expressions/imgs/pic06.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/01. Functions-and-Function-Expressions/imgs/pic06.png -------------------------------------------------------------------------------- /Topics/01. Functions-and-Function-Expressions/imgs/pic07.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/01. Functions-and-Function-Expressions/imgs/pic07.png -------------------------------------------------------------------------------- /Topics/01. Functions-and-Function-Expressions/imgs/pic08.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/01. Functions-and-Function-Expressions/imgs/pic08.png -------------------------------------------------------------------------------- /Topics/01. Functions-and-Function-Expressions/imgs/pic09.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/01. Functions-and-Function-Expressions/imgs/pic09.png -------------------------------------------------------------------------------- /Topics/01. Functions-and-Function-Expressions/imgs/pic11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/01. Functions-and-Function-Expressions/imgs/pic11.png -------------------------------------------------------------------------------- /Topics/01. Functions-and-Function-Expressions/imgs/pic12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/01. Functions-and-Function-Expressions/imgs/pic12.png -------------------------------------------------------------------------------- /Topics/01. Functions-and-Function-Expressions/imgs/pic13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/01. Functions-and-Function-Expressions/imgs/pic13.png -------------------------------------------------------------------------------- /Topics/01. Functions-and-Function-Expressions/imgs/pic14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/01. Functions-and-Function-Expressions/imgs/pic14.png -------------------------------------------------------------------------------- /Topics/01. Functions-and-Function-Expressions/imgs/pic15.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/01. Functions-and-Function-Expressions/imgs/pic15.png -------------------------------------------------------------------------------- /Topics/01. Functions-and-Function-Expressions/imgs/pic16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/01. Functions-and-Function-Expressions/imgs/pic16.png -------------------------------------------------------------------------------- /Topics/01. Functions-and-Function-Expressions/imgs/pic17.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/01. Functions-and-Function-Expressions/imgs/pic17.png -------------------------------------------------------------------------------- /Topics/01. Functions-and-Function-Expressions/imgs/pic18.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/01. Functions-and-Function-Expressions/imgs/pic18.png -------------------------------------------------------------------------------- /Topics/01. Functions-and-Function-Expressions/imgs/pic19.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/01. Functions-and-Function-Expressions/imgs/pic19.png -------------------------------------------------------------------------------- /Topics/01. Functions-and-Function-Expressions/imgs/pic20.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/01. Functions-and-Function-Expressions/imgs/pic20.png -------------------------------------------------------------------------------- /Topics/01. Functions-and-Function-Expressions/imgs/pic21.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/01. Functions-and-Function-Expressions/imgs/pic21.png -------------------------------------------------------------------------------- /Topics/01. Functions-and-Function-Expressions/imgs/pic22.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/01. Functions-and-Function-Expressions/imgs/pic22.png -------------------------------------------------------------------------------- /Topics/01. Functions-and-Function-Expressions/imgs/pic23.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/01. Functions-and-Function-Expressions/imgs/pic23.png -------------------------------------------------------------------------------- /Topics/01. Functions-and-Function-Expressions/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Course Introduction 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 26 | 27 | 28 | 29 |
30 |
31 |
32 | 33 | 34 | 35 | 36 | 37 | 38 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /Topics/02. Closures-and-Scope/demos/1. function-scope.js: -------------------------------------------------------------------------------- 1 | if (true) { 2 | //uncomment to create function scope 3 | //(function(){ 4 | var result = 'From the if'; 5 | //}()); 6 | } 7 | console.log(result); -------------------------------------------------------------------------------- /Topics/02. Closures-and-Scope/demos/1. scopes-global.js: -------------------------------------------------------------------------------- 1 | function stringRepeat(ch, times) { 2 | //global variable 3 | //'use strict' //solves this 4 | str = ''; 5 | for (var i = 0; i < times; i += 1) { 6 | str += ch; 7 | } 8 | return str; 9 | } 10 | 11 | console.log(stringRepeat('-', 20)); 12 | console.log(str); -------------------------------------------------------------------------------- /Topics/02. Closures-and-Scope/demos/3. scope-chain.js: -------------------------------------------------------------------------------- 1 | function outer() { 2 | var x = 'OUTER'; 3 | 4 | function inner() { 5 | var x = 'INNER'; 6 | return x; 7 | } 8 | inner(); 9 | return { 10 | x: x, 11 | f: inner 12 | }; 13 | } 14 | 15 | console.log(outer().x); 16 | console.log(outer().f()); 17 | -------------------------------------------------------------------------------- /Topics/02. Closures-and-Scope/demos/4. block-scope-let.js: -------------------------------------------------------------------------------- 1 | if (false) { 2 | var x = 5; 3 | let y = 6; 4 | } 5 | console.log(x); 6 | //works only if run with Babel or Traceur 7 | console.log(y); 8 | -------------------------------------------------------------------------------- /Topics/02. Closures-and-Scope/demos/5. closures.js: -------------------------------------------------------------------------------- 1 | function outer(x) { 2 | function middle(y) { 3 | function inner(z) { 4 | return x + ' ' + y + ' ' + z; 5 | } 6 | return inner; 7 | } 8 | return middle; 9 | } 10 | 11 | 12 | var system = outer(4); 13 | system = system(4); 14 | system = system(2); 15 | console.log('System ' + system); 16 | 17 | var names = outer('Peter'); 18 | names = names('Georgiev'); 19 | names = names('Petrov'); 20 | console.log('Hi! I am ' + names); -------------------------------------------------------------------------------- /Topics/02. Closures-and-Scope/demos/6. closures-usage.js: -------------------------------------------------------------------------------- 1 | var database = function () { 2 | var records, 3 | lastId, 4 | self; 5 | 6 | function findRecordById(id) { 7 | var i, 8 | record; 9 | if (!records) { 10 | return null; 11 | } 12 | for (i = 0; i < records.length; i += 1) { 13 | record = records[i]; 14 | if (record.id === id) { 15 | return record; 16 | } 17 | } 18 | return null; 19 | } 20 | 21 | function saveRecord(record) { 22 | if (!lastId) { 23 | lastId = 0; 24 | } 25 | if (!records) { 26 | records = []; 27 | } 28 | record.id = ++lastId; 29 | records.push(record); 30 | return self; 31 | } 32 | 33 | function getAllRecords() { 34 | var clonedRecords, 35 | i; 36 | clonedRecords = []; 37 | clonedRecords[records.length - 1] = undefined; 38 | for (i = 0; i < records.length; i += 1) { 39 | clonedRecords[i] = records[i]; 40 | } 41 | return clonedRecords; 42 | } 43 | 44 | self = { 45 | save: saveRecord, 46 | findById: findRecordById, 47 | getAll: getAllRecords 48 | }; 49 | 50 | return self; 51 | }(); 52 | 53 | 54 | database.save({ 55 | name: 'Peter', 56 | age: 13 57 | }).save({ 58 | name: 'Gosho', 59 | age: 17 60 | }).save(database); 61 | 62 | console.log(database.getAll()); 63 | console.log(database.findById(3)); -------------------------------------------------------------------------------- /Topics/02. Closures-and-Scope/homework/README.md: -------------------------------------------------------------------------------- 1 | # Closures and Scopes 2 | 3 | ### Task 1. 4 | 5 | - Create a module for working with books 6 | - The module must provide the following functionalities: 7 | - **Add a new book to category** 8 | - Each book has unique title, author and ISBN 9 | - It must return the newly created book with assigned ID 10 | - If the category is missing, it must be automatically created 11 | - **List all books** 12 | - Return an array of books 13 | - Books are sorted by ID 14 | - This can be done by author, by category or all 15 | - They are provided by an options object {category: ...} or {author: ...} 16 | - **List all categories** 17 | - Return an array of categories 18 | - Categories are sorted by ID 19 | - **Each book/category has a unique identifier (ID) that is a number greater than 1** 20 | - When adding a book/category, the ID is generated automatically 21 | - **Add validation everywhere, where possible** 22 | - Book title and category name must be between 2 and 100 characters, including letters, digits and special characters ('!', ',', '.', etc) 23 | - Author is any non-empty string 24 | - Unique params are Book title and Book ISBN 25 | - Book ISBN is an unique code that contains either 10 or 13 digits 26 | - If something is not valid - throw Error 27 | - **You are given a solution template in the [tasks/task-1.js](./tasks/task-1.js) file** 28 | -------------------------------------------------------------------------------- /Topics/02. Closures-and-Scope/homework/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "test-driven-hw-mocha", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "mocha -R spec tests" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "devDependencies": { 12 | "chai": "^3.5.0", 13 | "mocha": "^3.2.0" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Topics/02. Closures-and-Scope/homework/tasks/task-1.js: -------------------------------------------------------------------------------- 1 | /* Task Description */ 2 | /* 3 | * Create a module for working with books 4 | * The module must provide the following functionalities: 5 | * Add a new book to category 6 | * Each book has unique title, author and ISBN 7 | * It must return the newly created book with assigned ID 8 | * If the category is missing, it must be automatically created 9 | * List all books 10 | * Books are sorted by ID 11 | * This can be done by author, by category or all 12 | * List all categories 13 | * Categories are sorted by ID 14 | * Each book/catagory has a unique identifier (ID) that is a number greater than or equal to 1 15 | * When adding a book/category, the ID is generated automatically 16 | * Add validation everywhere, where possible 17 | * Book title and category name must be between 2 and 100 characters, including letters, digits and special characters ('!', ',', '.', etc) 18 | * Author is any non-empty string 19 | * Unique params are Book title and Book ISBN 20 | * Book ISBN is an unique code that contains either 10 or 13 digits 21 | * If something is not valid - throw Error 22 | */ 23 | function solve() { 24 | var library = (function () { 25 | var books = []; 26 | var categories = []; 27 | function listBooks() { 28 | return books; 29 | } 30 | 31 | function addBook(book) { 32 | book.ID = books.length + 1; 33 | books.push(book); 34 | return book; 35 | } 36 | 37 | function listCategories() { 38 | return categories; 39 | } 40 | 41 | return { 42 | books: { 43 | list: listBooks, 44 | add: addBook 45 | }, 46 | categories: { 47 | list: listCategories 48 | } 49 | }; 50 | } ()); 51 | return library; 52 | } 53 | module.exports = solve; 54 | -------------------------------------------------------------------------------- /Topics/02. Closures-and-Scope/imgs/closures.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/02. Closures-and-Scope/imgs/closures.png -------------------------------------------------------------------------------- /Topics/02. Closures-and-Scope/imgs/pic01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/02. Closures-and-Scope/imgs/pic01.png -------------------------------------------------------------------------------- /Topics/02. Closures-and-Scope/imgs/pic03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/02. Closures-and-Scope/imgs/pic03.png -------------------------------------------------------------------------------- /Topics/02. Closures-and-Scope/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Closures and Scope 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 26 | 27 | 28 | 29 |
30 |
31 |
32 | 33 | 34 | 35 | 36 | 37 | 38 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /Topics/03. Modules-and-Patterns/demos/1. module.js: -------------------------------------------------------------------------------- 1 | var controls = (function () { 2 | function formatResult(name, value) { 3 | return name + ' says the result is ' + value; 4 | } 5 | 6 | class Calculator { 7 | constructor(name) { 8 | this.name = name; 9 | this.result = 0; 10 | }; 11 | 12 | add(x) { 13 | x = +x; 14 | this.result += x; 15 | return this; 16 | }; 17 | 18 | subtract(x) { 19 | x = +x; 20 | this.result -= x; 21 | return this; 22 | }; 23 | 24 | showResult() { 25 | console.log(formatResult(this.name, this.result)); 26 | return this; 27 | }; 28 | }; 29 | 30 | return { getCalculator: (name) => new Calculator(name) }; 31 | } ()); 32 | 33 | var calc = controls.getCalculator('First'); 34 | calc.add(7); 35 | calc.showResult(); 36 | calc.subtract(2); 37 | calc.showResult(); 38 | -------------------------------------------------------------------------------- /Topics/03. Modules-and-Patterns/demos/2. revealing-module.js: -------------------------------------------------------------------------------- 1 | var controls = (function () { 2 | 3 | //hidden function 4 | function formatResult() { 5 | return this.name + ' says the result is ' + this.result; 6 | } 7 | 8 | class Calculator { 9 | constructor(name) { 10 | this.name = name; 11 | this.result = 0; 12 | }; 13 | 14 | add(x) { 15 | this.result += +x; 16 | return this; 17 | }; 18 | 19 | subtract(x) { 20 | this.result -= +x; 21 | return this; 22 | }; 23 | 24 | showResult() { 25 | console.log(formatResult.call(this)); 26 | return this; 27 | }; 28 | }; 29 | 30 | var getCalculator = (name) => new Calculator(name); 31 | 32 | //return only a reference to the function 33 | return { getCalculator }; 34 | } ()); 35 | 36 | var calc = controls.getCalculator('First') 37 | .add(7).showResult().subtract(2).showResult(); -------------------------------------------------------------------------------- /Topics/03. Modules-and-Patterns/demos/3. revealing-module.js: -------------------------------------------------------------------------------- 1 | var people = (function(){ 2 | var people = ['Will', 'Steve']; 3 | 4 | _render(); 5 | 6 | function _render() { // private function 7 | //console.clear(); 8 | console.log(people); 9 | } 10 | 11 | function addPerson(name) { 12 | people.push(name); 13 | _render(); 14 | } 15 | 16 | function deletePerson(i) { 17 | people.splice(i, 1); 18 | _render(); 19 | } 20 | 21 | return { 22 | addPerson: addPerson, 23 | deletePerson: deletePerson 24 | }; 25 | })(); 26 | 27 | people.addPerson("Jake"); 28 | people.deletePerson(0); -------------------------------------------------------------------------------- /Topics/03. Modules-and-Patterns/demos/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 9 | 10 | -------------------------------------------------------------------------------- /Topics/03. Modules-and-Patterns/homework/README.md: -------------------------------------------------------------------------------- 1 | # Modules and patterns 2 | ================================== 3 | 4 | ### Task 1. 5 | * Create a module for a `Telerik Academy course` 6 | * The course has a `title` and `presentations` 7 | * Each presentation also has a `title` 8 | * There is a homework for each presentation 9 | * There is a set of students listed for the course 10 | * Each student has `firstname`, `lastname` and an `ID` 11 | * IDs must be unique integer numbers which are at least 1 12 | * Each student can submit a homework for each presentation in the course 13 | * Create method `init()` 14 | * Accepts a `string` - course title 15 | * Accepts an `array of strings` - presentation titles 16 | * Throws if there is an invalid title 17 | * Titles do not start or end with spaces 18 | * Titles do not have consecutive spaces 19 | * Titles have at least one character 20 | * Throws if there are no presentations 21 | * Create method `addStudent()` which lists a student for the course 22 | * Accepts a string in the format `'Firstname Lastname'` 23 | * Throws if any of the names are not valid 24 | * Names start with an upper case letter 25 | * All other symbols in the name (if any) are lowercase letters 26 | * Generates a unique student ID and returns it 27 | * Create method `getAllStudents()` that returns an array of students in the format: 28 | * {firstname: 'string', lastname: 'string', id: StudentID} 29 | * Create method `submitHomework()` 30 | * Accepts `studentID` and `homeworkID` 31 | * homeworkID 1 is for the first presentation 32 | * homeworkID 2 is for the second one 33 | * ... 34 | * Throws if any of the IDs are invalid 35 | * Create method `pushExamResults()` 36 | * Accepts an array of items in the format `{StudentID: ..., score: ...}` 37 | * StudentIDs which are not listed get 0 points 38 | * Throw if there is an invalid StudentID 39 | * Throw if same StudentID is given more than once ( he tried to cheat (: ) 40 | * Throw if Score is not a number 41 | * Create method `getTopStudents()` which returns an array of the top **10 performing students** 42 | * Array must be sorted from **best to worst** 43 | * If there are less than 10, return them all 44 | * The final score that is used to calculate the top performing students is done as follows: 45 | * 75% of the exam result 46 | * 25% the submitted homework (count of submitted homeworks / count of all homeworks) for the course 47 | -------------------------------------------------------------------------------- /Topics/03. Modules-and-Patterns/homework/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "test-driven-hw-mocha", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "mocha -R spec tests" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "devDependencies": { 12 | "chai": "^3.5.0", 13 | "mocha": "^3.2.0" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Topics/03. Modules-and-Patterns/homework/tasks/task-1.js: -------------------------------------------------------------------------------- 1 | /* Task Description */ 2 | /* 3 | * Create a module for a Telerik Academy course 4 | * The course has a title and presentations 5 | * Each presentation also has a title 6 | * There is a homework for each presentation 7 | * There is a set of students listed for the course 8 | * Each student has firstname, lastname and an ID 9 | * IDs must be unique integer numbers which are at least 1 10 | * Each student can submit a homework for each presentation in the course 11 | * Create method init 12 | * Accepts a string - course title 13 | * Accepts an array of strings - presentation titles 14 | * Throws if there is an invalid title 15 | * Titles do not start or end with spaces 16 | * Titles do not have consecutive spaces 17 | * Titles have at least one character 18 | * Throws if there are no presentations 19 | * Create method addStudent which lists a student for the course 20 | * Accepts a string in the format 'Firstname Lastname' 21 | * Throws if any of the names are not valid 22 | * Names start with an upper case letter 23 | * All other symbols in the name (if any) are lowercase letters 24 | * Generates a unique student ID and returns it 25 | * Create method getAllStudents that returns an array of students in the format: 26 | * {firstname: 'string', lastname: 'string', id: StudentID} 27 | * Create method submitHomework 28 | * Accepts studentID and homeworkID 29 | * homeworkID 1 is for the first presentation 30 | * homeworkID 2 is for the second one 31 | * ... 32 | * Throws if any of the IDs are invalid 33 | * Create method pushExamResults 34 | * Accepts an array of items in the format {StudentID: ..., Score: ...} 35 | * StudentIDs which are not listed get 0 points 36 | * Throw if there is an invalid StudentID 37 | * Throw if same StudentID is given more than once ( he tried to cheat (: ) 38 | * Throw if Score is not a number 39 | * Create method getTopStudents which returns an array of the top 10 performing students 40 | * Array must be sorted from best to worst 41 | * If there are less than 10, return them all 42 | * The final score that is used to calculate the top performing students is done as follows: 43 | * 75% of the exam result 44 | * 25% the submitted homework (count of submitted homeworks / count of all homeworks) for the course 45 | */ 46 | 47 | function solve() { 48 | var Course = { 49 | init: function(title, presentations) { 50 | }, 51 | addStudent: function(name) { 52 | }, 53 | getAllStudents: function() { 54 | }, 55 | submitHomework: function(studentID, homeworkID) { 56 | }, 57 | pushExamResults: function(results) { 58 | }, 59 | getTopStudents: function() { 60 | } 61 | }; 62 | 63 | return Course; 64 | } 65 | 66 | 67 | module.exports = solve; 68 | -------------------------------------------------------------------------------- /Topics/03. Modules-and-Patterns/imgs/pic00.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/03. Modules-and-Patterns/imgs/pic00.png -------------------------------------------------------------------------------- /Topics/03. Modules-and-Patterns/imgs/pic01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/03. Modules-and-Patterns/imgs/pic01.png -------------------------------------------------------------------------------- /Topics/03. Modules-and-Patterns/imgs/pic02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/03. Modules-and-Patterns/imgs/pic02.png -------------------------------------------------------------------------------- /Topics/03. Modules-and-Patterns/imgs/pic03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/03. Modules-and-Patterns/imgs/pic03.png -------------------------------------------------------------------------------- /Topics/03. Modules-and-Patterns/imgs/pic04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/03. Modules-and-Patterns/imgs/pic04.png -------------------------------------------------------------------------------- /Topics/03. Modules-and-Patterns/imgs/pic05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/03. Modules-and-Patterns/imgs/pic05.png -------------------------------------------------------------------------------- /Topics/03. Modules-and-Patterns/imgs/pic06.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/03. Modules-and-Patterns/imgs/pic06.png -------------------------------------------------------------------------------- /Topics/03. Modules-and-Patterns/imgs/pic07.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/03. Modules-and-Patterns/imgs/pic07.png -------------------------------------------------------------------------------- /Topics/03. Modules-and-Patterns/imgs/pic08.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/03. Modules-and-Patterns/imgs/pic08.png -------------------------------------------------------------------------------- /Topics/03. Modules-and-Patterns/imgs/pic09.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/03. Modules-and-Patterns/imgs/pic09.png -------------------------------------------------------------------------------- /Topics/03. Modules-and-Patterns/imgs/pic10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/03. Modules-and-Patterns/imgs/pic10.png -------------------------------------------------------------------------------- /Topics/03. Modules-and-Patterns/imgs/pic11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/03. Modules-and-Patterns/imgs/pic11.png -------------------------------------------------------------------------------- /Topics/03. Modules-and-Patterns/imgs/pic12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/03. Modules-and-Patterns/imgs/pic12.png -------------------------------------------------------------------------------- /Topics/03. Modules-and-Patterns/imgs/pic13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/03. Modules-and-Patterns/imgs/pic13.png -------------------------------------------------------------------------------- /Topics/03. Modules-and-Patterns/imgs/pic14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/03. Modules-and-Patterns/imgs/pic14.png -------------------------------------------------------------------------------- /Topics/03. Modules-and-Patterns/imgs/pic15.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/03. Modules-and-Patterns/imgs/pic15.png -------------------------------------------------------------------------------- /Topics/03. Modules-and-Patterns/imgs/pic16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/03. Modules-and-Patterns/imgs/pic16.png -------------------------------------------------------------------------------- /Topics/03. Modules-and-Patterns/imgs/pic17.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/03. Modules-and-Patterns/imgs/pic17.png -------------------------------------------------------------------------------- /Topics/03. Modules-and-Patterns/imgs/pic18.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/03. Modules-and-Patterns/imgs/pic18.png -------------------------------------------------------------------------------- /Topics/03. Modules-and-Patterns/imgs/pic19.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/03. Modules-and-Patterns/imgs/pic19.png -------------------------------------------------------------------------------- /Topics/03. Modules-and-Patterns/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Modules and Patterns 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 26 | 27 | 28 | 29 |
30 |
31 |
32 | 33 | 34 | 35 | 36 | 37 | 38 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /Topics/04. Classes-and-Class-Constructors/README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # ES6 Classes and Class Constructors 4 | 5 |
6 |

JavaScript OOP

7 |

Telerik Software Academy

8 | https://telerikacademy.com 9 |
10 | 11 | 12 | 13 | 14 | 15 | # Table of Contents 16 | - [What is a class?](#classes) 17 | - [What are ES6 classes?](#es6-classes) 18 | - Creating and using ES6 classes 19 | - [Constructors](#constructors) 20 | 21 | 22 | 23 | # Classes 24 | ## What is a class? 25 | 26 | 27 | 28 | - Classes in general are used as **blueprints or templates for creation of objects**. Classes gives us a way to: 29 | - Create objects that have similar properties and behaviour 30 | - Reuse code and functionality between different object via **inheritance** 31 | - Hide implementation details and expose only what is needed - **encapsulation** and **abstraction** 32 | - Treat objects that have similar behaviour, but different concrete types, the same - **polymorphism** 33 | 34 | 35 | # ES6 Classes 36 | - ES6 introduces the `class` keyword 37 | - Classes in JavaScript are actually functions 38 | 39 | ```js 40 | class Superhero { 41 | 42 | } 43 | 44 | console.log(typeof Superhero); // logs 'function' 45 | ``` 46 | 47 | 48 | 49 | 50 | - Lets create a class that has some data and use the class to create an object of that type: 51 | - an object of a class is created by calling the **class name** as a function with the `new` operator. 52 | 53 | ```js 54 | class Horse { 55 | constructor(name, furColor, age) { 56 | this._name = name; 57 | this._furColor = furColor; 58 | this._age = age; 59 | } 60 | } 61 | 62 | const horse = new Horse('Trendafil', 'brown', 2); 63 | console.log(horse); 64 | // { _name: 'Trendafil', _furColor: 'brown', age: 2 } 65 | ``` 66 | 67 | 68 | # The `new` keyword 69 | - What happens when a function is called with the `new` keyword? 70 | 71 | ```js 72 | function F() { 73 | console.log(this); 74 | this.prop = 'hello'; 75 | }; 76 | 77 | const f = new F(); 78 | console.log(f); // { prop: 'hello' } 79 | ``` 80 | 81 | 82 | 83 | - The `new` keyword sets the **context** of the function to a new object 84 | - The result of the function execution will be the new object 85 | 86 | 87 | # The `class constructor` 88 | - The `class constructor` is a kind-of-function that is called with `new` and is executed when an object of a class is created 89 | - In the following example the **class constructor** will be called with its context set to a new object `{}` 90 | 91 | ```js 92 | class Horse { 93 | constructor(name, furColor, age) { 94 | this._name = name; 95 | this._furColor = furColor; 96 | this._age = age; 97 | } 98 | } 99 | 100 | const horse = new Horse('Trendafil', 'brown', 2); 101 | ``` 102 | 103 | 104 | 105 | - **Class constructors** are obligatory and can be omitted. The following two snippets are equivalent: 106 | 107 | ```js 108 | class Superhero { } 109 | 110 | const gosho = new Superhero(); 111 | ``` 112 | 113 | ```js 114 | class Superhero { 115 | constructor() { } 116 | } 117 | 118 | const gosho = new Superhero(); 119 | ``` 120 | 121 | 122 | 123 | 124 | 125 | 127 | 128 | 129 | # Free Trainings @ Telerik Academy 130 | - "Web Design with HTML 5, CSS 3 and JavaScript" course @ Telerik Academy 131 | - [javascript course](http://academy.telerik.com/student-courses/web-design-and-ui/javascript-fundamentals/about) 132 | - Telerik Software Academy 133 | - [telerikacademy.com](https://telerikacademy.com) 134 | - Telerik Academy @ Facebook 135 | - [facebook.com/TelerikAcademy](https://facebook.com/TelerikAcademy) 136 | - Telerik Software Academy Forums 137 | - [forums.academy.telerik.com](https://telerikacademy.com/Forum/Home) 138 | 139 | 140 | -------------------------------------------------------------------------------- /Topics/04. Classes-and-Class-Constructors/demos/demo.js: -------------------------------------------------------------------------------- 1 | console.log('04. Classes-and-Class-Constructors'); -------------------------------------------------------------------------------- /Topics/04. Classes-and-Class-Constructors/homework/README.md: -------------------------------------------------------------------------------- 1 | # 04. Classes-and-Class-Constructors Homeworks 2 | -------------------------------------------------------------------------------- /Topics/04. Classes-and-Class-Constructors/imgs/es6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/04. Classes-and-Class-Constructors/imgs/es6.png -------------------------------------------------------------------------------- /Topics/04. Classes-and-Class-Constructors/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Classes and Class Constructors 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 26 | 27 | 28 | 29 |
30 |
31 |
32 | 33 | 34 | 35 | 36 | 37 | 38 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /Topics/05. Class-Methods-and-Properties/demos/demo.js: -------------------------------------------------------------------------------- 1 | console.log('05. Class-Methods-and-Properties'); 2 | -------------------------------------------------------------------------------- /Topics/05. Class-Methods-and-Properties/homework/README.md: -------------------------------------------------------------------------------- 1 | # 05. Class-Methods-and-Properties Homeworks 2 | - [Task 1 - Linked List](./task-1) -------------------------------------------------------------------------------- /Topics/05. Class-Methods-and-Properties/homework/task-1/README.md: -------------------------------------------------------------------------------- 1 | # Linked list 2 | - Implement a **linked list** using **ES6 classes**. Use two classes - `LinkedList` and `listNode`. Look at the hints at the bottom of the description. Your class implementation should: 3 | 4 | ### Getters 5 | - have a getter `first` - return the value of the first node in the list 6 | - have a getter `last` - return the value of the last node in the list 7 | - have a getter `length` for the length of the linked list 8 | 9 | ### Methods 10 | - provide a method `append(el1, el2, el3...)` that adds the provided elements to the end of the list 11 | - should enable chaining 12 | 13 | ```js 14 | const list = new LinkedList(); 15 | list.append(1, 2, 3).append(4); 16 | // list should contain 1, 2, 3 and 4 17 | ``` 18 | 19 | - provide a method `prepend(el1, el2, el3...)` that adds the provided elements to the beggining of the list 20 | - should enable chaining 21 | 22 | ```js 23 | const list = new LinkedList(); 24 | list.append(4, 5, 6).prepend(1, 2, 3); 25 | // should contain 1, 2, 3, 4, 5, 6 in that order 26 | ``` 27 | 28 | - provide a method `insert(index, el1, el2, el3...)` for inserting values at the specified index 29 | - should enable chaining 30 | 31 | ```js 32 | const list = new LinkedList(); 33 | list.append(1, 4, 5).insert(1, 2, 3); 34 | // list should contain 1, 2, 3, 4, 5 35 | ``` 36 | 37 | - provide a method `at(index[, value])` for indexing 38 | - when passed an **index**, it should return the element at that **index** 39 | - when passed an **index** and a **value**, should change the value of the element at that index 40 | 41 | ```js 42 | const list = new LinkedList(); 43 | list.append(1, 2, 3, 4, 5, 6); 44 | console.log(list.at(2)); // 3 45 | 46 | list.at(2, 'gosho'); 47 | console.log(list.at(2)); // gosho 48 | ``` 49 | 50 | - provide a method `removeAt(index)` that removes an element at a given index 51 | - should return the removed element 52 | 53 | ```js 54 | const list = new LinkedList(); 55 | 56 | const removed = list.append(1, 2, 3, 4, 5).removeAt(1); 57 | // removed should be 2 58 | // the list should contain 1, 3, 4, 5 59 | ``` 60 | 61 | - your class should be **iterable with a for-of loop** 62 | - you must use `Symbol.iterator` 63 | 64 | ```js 65 | class LinkedList { 66 | /* 67 | other code here 68 | */ 69 | 70 | * [Symbol.iterator] { 71 | // iterator code 72 | } 73 | } 74 | 75 | const list = new LinkedList().append(6, 7, 8).prepend(1, 2, 3, 4, 5); 76 | 77 | for(const value of list) { 78 | console.log(value); 79 | } 80 | // output should be the numbers [1..8], each on a separate line 81 | ``` 82 | 83 | - provide a `toArray()` method, that converts the linked list to an array 84 | 85 | ```js 86 | const list = new LinkedList(); 87 | list.append(1, 2, 3, 4, 5, 6); 88 | 89 | const arr = list.toArray(); 90 | console.log(arr); // [1, 2, 3, 4, 5, 6] 91 | console.log(arr instanceof Array); // true 92 | ``` 93 | 94 | - provide method `toString()`, which should return a string representation of the linked list - the values of the elements, separated by **' -> '** 95 | 96 | ```js 97 | const list = new LinkedList(); 98 | list.append(1, 2, 3, 4, 5, 6); 99 | 100 | console.log(list.toString()); // 1 -> 2 -> 3 -> 4 -> 5 -> 6 101 | ``` 102 | 103 | #### Hints 104 | - Read about the linked list data structure on the internet. 105 | - You can watch [this video](https://youtu.be/WmwuLvxqmac?t=394). 106 | - You can try reading [this article](https://www.nczonline.net/blog/2009/04/13/computer-science-in-javascript-linked-list/). 107 | - Research on your own :) 108 | - Read about chaining in programming and fluent interfaces. 109 | - The **[spread operator](https://rainsoft.io/how-three-dots-changed-javascript/)**(`...`) might help you a bit with arguments. 110 | - Implementing **for-of** [iteration](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators) first will help you with implementing `toArray` and `toString`. 111 | - Research ES2016 generator functions. 112 | - Research how to make an object iterable. 113 | - Try to reuse already implemented functionalities. Implemented iteration can be used for `toArray`. `toArray` can be used for `toString`. You can also reuse code between `append`, `prepend` and `insert`. 114 | 115 | #### Running the tests locally 116 | - Run `npm install` in this directory to download the dependencies in `package.json` (mocha and chai). 117 | - Run `npm test` to run the tests. 118 | -------------------------------------------------------------------------------- /Topics/05. Class-Methods-and-Properties/homework/task-1/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "task", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "task-1.js", 6 | "directories": { 7 | "test": "tests" 8 | }, 9 | "scripts": { 10 | "test": "mocha -R spec tests" 11 | }, 12 | "author": "", 13 | "license": "ISC", 14 | "dependencies": { 15 | "chai": "^3.5.0", 16 | "mocha": "^3.0.2" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Topics/05. Class-Methods-and-Properties/homework/task-1/task/task-1.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | class listNode { 4 | constructor(value) { 5 | 6 | } 7 | } 8 | 9 | class LinkedList { 10 | constructor() { 11 | 12 | } 13 | } 14 | 15 | module.exports = LinkedList; -------------------------------------------------------------------------------- /Topics/05. Class-Methods-and-Properties/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Class Methods and Properties 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 26 | 27 | 28 | 29 |
30 |
31 |
32 | 33 | 34 | 35 | 36 | 37 | 38 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /Topics/06. Class-Inheritance/README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Class Inheritance 4 | 5 |
6 |

JavaScript OOP

7 |

Telerik Software Academy

8 | https://telerikacademy.com 9 |
10 | 11 | 12 | 13 | # Table of Contents 14 | - [What is inheritance](#inheritance) 15 | - [Inheritance in ES6](#es6) 16 | - Super class calls 17 | 18 | 19 | 20 | # Inheritance 21 | 22 | 23 | 24 | - **Inheritance** allows child classes to inherit the characteristics of an existing parent (base) class 25 | - Attributes (fields and properties) 26 | - Operations (methods) 27 | - Child class can extend the parent class 28 | - Add new fields and methods 29 | - Redefine methods (modify existing behavior) 30 | 31 | 32 | 33 | - **Inheritance** has a lot of benefits 34 | - Extensibility 35 | - Reusability (`code reuse`) 36 | - Provides abstraction 37 | - Eliminates redundant code 38 | - Use inheritance for building `is-a` relationships 39 | - E.g. dog `is-a` animal (dogs are kind of animals) 40 | - Don't use it to build `has-a` relationship 41 | - E.g. dog `has-a` name (dog is not kind of name) 42 | 43 | 44 | 45 | - **Inheritance** implicitly gains all members from another class 46 | - All fields, methods, properties, events, … 47 | - Some members could be inaccessible (hidden) 48 | - The class whose methods are inherited is called base (parent) class 49 | - The class that gains new functionality is called derived (child) class 50 | 51 | 52 | 53 | # Classes and Inheritance in ES6 54 | 55 | 56 | 57 | - ES6 introduces classes and a way to create classical OOP 58 | - Using the `class` keyword 59 | 60 | ```javascript 61 | class Mammal { 62 | constructor(age) { 63 | this._age = age; 64 | } 65 | } 66 | ``` 67 | 68 | 69 | 70 | - Sub classing is done using the `extends` keyword 71 | 72 | ```javascript 73 | class Mammal { 74 | speak(str) { 75 | // mammals usually don't speak 76 | } 77 | } 78 | 79 | class Person extends Mammal { 80 | speak(str) { 81 | console.log(str); 82 | } 83 | } 84 | ``` 85 | 86 | 87 | 88 | - `super` is used to refer to the parent class 89 | - `super()` calls the parent constructor 90 | - needed in order for `this` to refer to the correct object 91 | - `super.method()` calls `.method()` from the parent class 92 | 93 | 94 | 95 | ```javascript 96 | class Person extends Mammal { 97 | constructor(fname, lname, age) { 98 | super(age); 99 | this._fname = fname; 100 | this._lname = lname; 101 | } 102 | get fullname() { 103 | // getter property of fullname 104 | } 105 | set fullname(newfullname) { 106 | // setter property of fullname 107 | } 108 | // more class members… 109 | } 110 | ``` 111 | 112 |
Constructor of the class
113 |
Getters and setters
114 | 115 | 116 | 117 | 118 | 120 | 121 | 122 | # Free Trainings
@ Telerik Academy 123 | - "Web Design with HTML 5, CSS 3 and JavaScript" course @ Telerik Academy 124 | - [javascript course](http://academy.telerik.com/student-courses/web-design-and-ui/javascript-fundamentals/about) 125 | - Telerik Software Academy 126 | - [https://telerikacademy.com](https://telerikacademy.com) 127 | - Telerik Academy @ Facebook 128 | - [facebook.com/TelerikAcademy](https://facebook.com/TelerikAcademy) 129 | - Telerik Software Academy Forums 130 | - [https://telerikacademy.com/Forum/Home](https://telerikacademy.com/Forum/Home) 131 | -------------------------------------------------------------------------------- /Topics/06. Class-Inheritance/demos/pet-store.js: -------------------------------------------------------------------------------- 1 | const petStore = (function () { 2 | 3 | class Animal { 4 | constructor(name, age, sound) { 5 | this.name = name; 6 | this.age = age; 7 | this.sound = sound; 8 | } 9 | 10 | get name() { 11 | return this._name; 12 | } 13 | 14 | set name(value) { 15 | if(typeof value !== 'string' || value.length < 2) { 16 | throw new Error('Name must be string value with at least 2 symbols!'); 17 | } 18 | 19 | this._name = value; 20 | } 21 | 22 | get age() { 23 | return this._age; 24 | } 25 | 26 | set age(value) { 27 | if(value < 0) { 28 | throw new Error('Age cannot be negative number!'); 29 | } 30 | 31 | this._age = value; 32 | } 33 | 34 | get sound() { 35 | return this._sound; 36 | } 37 | 38 | set sound(value) { 39 | if(typeof value !== 'string') { 40 | throw new Error('Sound must be string!'); 41 | } 42 | 43 | this._sound = value; 44 | } 45 | 46 | makeSound() { 47 | console.log(this.sound); 48 | } 49 | 50 | toString() { 51 | return `${this.name} is ${this.age} years old` 52 | } 53 | } 54 | 55 | class Cat extends Animal { 56 | constructor(name, age, color) { 57 | super(name, age, 'mew'); 58 | 59 | this.color = color; 60 | } 61 | 62 | toString() { 63 | return `${super.toString()} ${this.color} cat`; 64 | } 65 | } 66 | 67 | class MythicalDragonHydra extends Animal { 68 | constructor(name, age, headsCount) { 69 | super(name, age, 'RAWRWRWR'); 70 | 71 | if(headsCount < 2) { 72 | throw new Error('MythicalDragonHydra must have at least 2 heads!'); 73 | } 74 | 75 | this._headsCount = headsCount; 76 | } 77 | 78 | get headsCount() { 79 | return this._headsCount; 80 | } 81 | 82 | growHead() { 83 | this._headsCount += 1; 84 | this.makeSound(); 85 | } 86 | 87 | toString() { 88 | return `${super.toString()} and is a mythic dragon hydra with ${this.headsCount} heads!`; 89 | } 90 | } 91 | 92 | return { 93 | getCat: function(name, age, color) { 94 | return new Cat(name, age, color); 95 | }, 96 | getHydra: function(name, age, headsCount) { 97 | return new MythicalDragonHydra(name, age, headsCount); 98 | } 99 | }; 100 | } ()); 101 | 102 | const davinci = petStore.getCat('davinci', 2, 'gray'), 103 | petko = petStore.getHydra('petko', 1000, 5); 104 | 105 | davinci.makeSound(); 106 | console.log(davinci.toString()); 107 | 108 | petko.makeSound(); 109 | console.log(petko.toString()); -------------------------------------------------------------------------------- /Topics/06. Class-Inheritance/homework/README.md: -------------------------------------------------------------------------------- 1 | # 06. Class-Inheritance Homeworks 2 | -------------------------------------------------------------------------------- /Topics/06. Class-Inheritance/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Class Inheritance 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 26 | 27 | 28 | 29 |
30 |
31 |
32 | 33 | 34 | 35 | 36 | 37 | 38 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /Topics/07. ES2015-Features/demos/00. demo-compiled.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var arr = ['asd', 2, 3, 4, 5]; 4 | 5 | var _iteratorNormalCompletion = true; 6 | var _didIteratorError = false; 7 | var _iteratorError = undefined; 8 | 9 | try { 10 | for (var _iterator = arr[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { 11 | var i = _step.value; 12 | 13 | console.log(i); 14 | } 15 | } catch (err) { 16 | _didIteratorError = true; 17 | _iteratorError = err; 18 | } finally { 19 | try { 20 | if (!_iteratorNormalCompletion && _iterator['return']) { 21 | _iterator['return'](); 22 | } 23 | } finally { 24 | if (_didIteratorError) { 25 | throw _iteratorError; 26 | } 27 | } 28 | } 29 | 30 | //# sourceMappingURL=00. demo-compiled.js.map -------------------------------------------------------------------------------- /Topics/07. ES2015-Features/demos/00. demo-compiled.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["00. demo.js"],"names":[],"mappings":";;AAEA,IAAI,GAAG,GAAG,CAAC,KAAK,EAAC,CAAC,EAAC,CAAC,EAAC,CAAC,EAAC,CAAC,CAAC,CAAC;;;;;;;AAE1B,yBAAc,GAAG,8HAAE;YAAV,CAAC;;AACN,eAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;KAClB","file":"00. demo-compiled.js","sourcesContent":["\r\n\r\nvar arr = ['asd',2,3,4,5];\r\n\r\nfor (let i of arr) {\r\n console.log(i);\r\n}"]} -------------------------------------------------------------------------------- /Topics/07. ES2015-Features/demos/00. demo.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | var arr = ['asd',2,3,4,5]; 4 | 5 | for (let i of arr) { 6 | console.log(i); 7 | } -------------------------------------------------------------------------------- /Topics/07. ES2015-Features/demos/01. let and const-compiled.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | (function f() { 4 | { 5 | var x = undefined; 6 | { 7 | // okay, block scoped name 8 | var _x = "sneaky"; 9 | console.log(_x); 10 | // error, const 11 | //x = "foo"; 12 | } 13 | // error, already declared in block 14 | //let x = "inner"; 15 | } 16 | })(); 17 | 18 | //# sourceMappingURL=01. let and const-compiled.js.map -------------------------------------------------------------------------------- /Topics/07. ES2015-Features/demos/01. let and const-compiled.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["01. let and const.js"],"names":[],"mappings":";;AAAA,AAAC,CAAA,SAAS,CAAC,GAAG;AACV;AACI,YAAI,CAAC,YAAA,CAAC;AACN;;AAEI,gBAAM,EAAC,GAAG,QAAQ,CAAC;AACnB,mBAAO,CAAC,GAAG,CAAC,EAAC,CAAC,CAAC;;;SAGlB;;;KAGJ;CACJ,CAAA,EAAE,CAAE","file":"01. let and const-compiled.js","sourcesContent":["(function f() {\r\n {\r\n let x;\r\n {\r\n // okay, block scoped name\r\n const x = \"sneaky\";\r\n console.log(x);\r\n // error, const\r\n //x = \"foo\";\r\n }\r\n // error, already declared in block\r\n //let x = \"inner\";\r\n }\r\n}());"]} -------------------------------------------------------------------------------- /Topics/07. ES2015-Features/demos/01. let and const.js: -------------------------------------------------------------------------------- 1 | (function f() { 2 | { 3 | let x; 4 | { 5 | // okay, block scoped name 6 | const x = "sneaky"; 7 | // error, const 8 | x = "foo"; 9 | } 10 | // error, already declared in block 11 | let x = "inner"; 12 | } 13 | }()); -------------------------------------------------------------------------------- /Topics/07. ES2015-Features/demos/02. for-of loop-compiled.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } 4 | 5 | var fibonacci = _defineProperty({}, Symbol.iterator, function () { 6 | var pre = 0, 7 | cur = 1; 8 | return { 9 | next: function next() { 10 | var _ref = [cur, pre + cur]; 11 | pre = _ref[0]; 12 | cur = _ref[1]; 13 | 14 | return { done: false, value: cur }; 15 | } 16 | }; 17 | }); 18 | 19 | var _iteratorNormalCompletion = true; 20 | var _didIteratorError = false; 21 | var _iteratorError = undefined; 22 | 23 | try { 24 | for (var _iterator = fibonacci[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { 25 | var n = _step.value; 26 | 27 | // truncate the sequence at 1000 28 | if (n > 1000) break; 29 | console.log(n); 30 | } 31 | } catch (err) { 32 | _didIteratorError = true; 33 | _iteratorError = err; 34 | } finally { 35 | try { 36 | if (!_iteratorNormalCompletion && _iterator["return"]) { 37 | _iterator["return"](); 38 | } 39 | } finally { 40 | if (_didIteratorError) { 41 | throw _iteratorError; 42 | } 43 | } 44 | } 45 | 46 | //# sourceMappingURL=02. for-of loop-compiled.js.map -------------------------------------------------------------------------------- /Topics/07. ES2015-Features/demos/02. for-of loop-compiled.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["02. for-of loop.js"],"names":[],"mappings":";;;;AAAA,IAAI,SAAS,uBACR,MAAM,CAAC,QAAQ,EAAC,YAAG;AAChB,QAAI,GAAG,GAAG,CAAC;QAAE,GAAG,GAAG,CAAC,CAAC;AACrB,WAAO;AACH,YAAI,EAAA,gBAAG;uBACU,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,CAAC;AAA5B,eAAG;AAAE,eAAG;;AACT,mBAAO,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,CAAA;SACrC;KACJ,CAAA;CACJ,CACJ,CAAA;;;;;;;AAED,yBAAc,SAAS,8HAAE;YAAhB,CAAC;;;AAEN,YAAI,CAAC,GAAG,IAAI,EACR,MAAM;AACV,eAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;KAClB","file":"02. for-of loop-compiled.js","sourcesContent":["let fibonacci = {\r\n [Symbol.iterator]() {\r\n let pre = 0, cur = 1;\r\n return {\r\n next() {\r\n [pre, cur] = [cur, pre + cur];\r\n return { done: false, value: cur }\r\n }\r\n }\r\n }\r\n}\r\n\r\nfor (var n of fibonacci) {\r\n // truncate the sequence at 1000\r\n if (n > 1000)\r\n break;\r\n console.log(n);\r\n}"]} -------------------------------------------------------------------------------- /Topics/07. ES2015-Features/demos/02. for-of loop.js: -------------------------------------------------------------------------------- 1 | let fibonacci = { 2 | [Symbol.iterator]() { 3 | let pre = 0, cur = 1; 4 | return { 5 | next() { 6 | [pre, cur] = [cur, pre + cur]; 7 | return { done: false, value: cur } 8 | } 9 | } 10 | } 11 | } 12 | 13 | for (var n of fibonacci) { 14 | // truncate the sequence at 1000 15 | if (n > 1000) 16 | break; 17 | console.log(n); 18 | } -------------------------------------------------------------------------------- /Topics/07. ES2015-Features/demos/03. templated string-compiled.js: -------------------------------------------------------------------------------- 1 | // Basic literal string creation 2 | "use strict"; 3 | 4 | console.log("In ES5 \"\n\" is a line-feed."); 5 | 6 | // Multiline strings 7 | console.log("In ES5 this is\nnot legal."); 8 | 9 | // Interpolate variable bindings 10 | var name = "Bob", 11 | time = "today"; 12 | console.log("Hello " + name + ", how are you " + time + "?"); 13 | 14 | //# sourceMappingURL=03. templated string-compiled.js.map -------------------------------------------------------------------------------- /Topics/07. ES2015-Features/demos/03. templated string-compiled.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["03. templated string.js"],"names":[],"mappings":";;;AACA,OAAO,CAAC,GAAG,iCAA+B,CAAC;;;AAG3C,OAAO,CAAC,GAAG,8BACC,CAAC;;;AAGb,IAAI,IAAI,GAAG,KAAK;IAAE,IAAI,GAAG,OAAO,CAAC;AACjC,OAAO,CAAC,GAAG,YAAU,IAAI,sBAAiB,IAAI,OAAI,CAAC","file":"03. templated string-compiled.js","sourcesContent":["// Basic literal string creation\r\nconsole.log(`In ES5 \"\\n\" is a line-feed.`);\r\n\r\n// Multiline strings\r\nconsole.log(`In ES5 this is\r\nnot legal.`);\r\n\r\n// Interpolate variable bindings\r\nvar name = \"Bob\", time = \"today\";\r\nconsole.log(`Hello ${name}, how are you ${time}?`);"]} -------------------------------------------------------------------------------- /Topics/07. ES2015-Features/demos/03. templated string.js: -------------------------------------------------------------------------------- 1 | // Basic literal string creation 2 | console.log(`In ES5 "\n" is a line-feed.`); 3 | 4 | // Multiline strings 5 | console.log(`In ES5 this is 6 | not legal.`); 7 | 8 | // Interpolate variable bindings 9 | var name = "Bob", time = "today"; 10 | console.log(`Hello ${name}, how are you ${time}?`); -------------------------------------------------------------------------------- /Topics/07. ES2015-Features/demos/04. classes and inheritance-compiled.js: -------------------------------------------------------------------------------- 1 | // Definition 2 | "use strict"; 3 | 4 | var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; desc = parent = getter = undefined; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; continue _function; } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; 5 | 6 | var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); 7 | 8 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; } 9 | 10 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } 11 | 12 | var Shape = (function () { 13 | function Shape(id, x, y) { 14 | _classCallCheck(this, Shape); 15 | 16 | this.id = id; 17 | this.move(x, y); 18 | } 19 | 20 | _createClass(Shape, [{ 21 | key: "move", 22 | value: function move(x, y) { 23 | this.x = x; 24 | this.y = y; 25 | } 26 | }, { 27 | key: "toString", 28 | value: function toString() { 29 | return "Shape(" + this.id + ")"; 30 | } 31 | }]); 32 | 33 | return Shape; 34 | })(); 35 | 36 | // Inheritance 37 | 38 | var Rectangle = (function (_Shape) { 39 | function Rectangle(id, x, y, width, height) { 40 | _classCallCheck(this, Rectangle); 41 | 42 | _get(Object.getPrototypeOf(Rectangle.prototype), "constructor", this).call(this, id, x, y); 43 | this.width = width; 44 | this.height = height; 45 | } 46 | 47 | _inherits(Rectangle, _Shape); 48 | 49 | _createClass(Rectangle, [{ 50 | key: "toString", 51 | value: function toString() { 52 | return "Rectangle > " + _get(Object.getPrototypeOf(Rectangle.prototype), "toString", this).call(this); 53 | } 54 | }], [{ 55 | key: "defaultRectangle", 56 | value: function defaultRectangle() { 57 | return new Rectangle("default", 0, 0, 100, 100); 58 | } 59 | }]); 60 | 61 | return Rectangle; 62 | })(Shape); 63 | 64 | var Circle = (function (_Shape2) { 65 | function Circle(id, x, y, radius) { 66 | _classCallCheck(this, Circle); 67 | 68 | _get(Object.getPrototypeOf(Circle.prototype), "constructor", this).call(this, id, x, y); 69 | this.radius = radius; 70 | } 71 | 72 | _inherits(Circle, _Shape2); 73 | 74 | _createClass(Circle, [{ 75 | key: "toString", 76 | value: function toString() { 77 | return "Circle > " + _get(Object.getPrototypeOf(Circle.prototype), "toString", this).call(this); 78 | } 79 | }], [{ 80 | key: "defaultCircle", 81 | value: function defaultCircle() { 82 | return new Circle("default", 0, 0, 100); 83 | } 84 | }]); 85 | 86 | return Circle; 87 | })(Shape); 88 | 89 | var rect = new Rectangle(1, 10, 20, 10, 20); 90 | console.log(rect); 91 | console.log(rect.toString()); 92 | 93 | var circle = new Circle(2, 0, 0, 10); 94 | console.log(circle); 95 | circle.move(10, 10); 96 | console.log(circle); 97 | console.log(circle.toString()); 98 | 99 | //# sourceMappingURL=04. classes and inheritance-compiled.js.map -------------------------------------------------------------------------------- /Topics/07. ES2015-Features/demos/04. classes and inheritance-compiled.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["04. classes and inheritance.js"],"names":[],"mappings":";;;;;;;;;;;IACM,KAAK;AACK,aADV,KAAK,CACM,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE;8BADrB,KAAK;;AAEH,YAAI,CAAC,EAAE,GAAG,EAAE,CAAC;AACb,YAAI,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;KACnB;;iBAJC,KAAK;;eAKF,cAAC,CAAC,EAAE,CAAC,EAAE;AACR,gBAAI,CAAC,CAAC,GAAG,CAAC,CAAC;AACX,gBAAI,CAAC,CAAC,GAAG,CAAC,CAAC;SACd;;;eACQ,oBAAG;AACR,8BAAgB,IAAI,CAAC,EAAE,OAAI;SAC9B;;;WAXC,KAAK;;;;;IAeL,SAAS;AACC,aADV,SAAS,CACE,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE;8BADpC,SAAS;;AAEP,mCAFF,SAAS,6CAED,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE;AAChB,YAAI,CAAC,KAAK,GAAI,KAAK,CAAC;AACpB,YAAI,CAAC,MAAM,GAAG,MAAM,CAAC;KACxB;;cALC,SAAS;;iBAAT,SAAS;;eAMF,oBAAG;AACR,mBAAO,cAAc,8BAPvB,SAAS,yCAOiC,CAAC;SAC5C;;;eACuB,4BAAG;AACvB,mBAAO,IAAI,SAAS,CAAC,SAAS,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,CAAA;SAClD;;;WAXC,SAAS;GAAS,KAAK;;IAcvB,MAAM;AACI,aADV,MAAM,CACK,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE;8BAD7B,MAAM;;AAEJ,mCAFF,MAAM,6CAEE,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE;AAChB,YAAI,CAAC,MAAM,GAAG,MAAM,CAAC;KACxB;;cAJC,MAAM;;iBAAN,MAAM;;eAKC,oBAAG;AACR,mBAAO,WAAW,8BANpB,MAAM,yCAMiC,CAAC;SACzC;;;eACoB,yBAAG;AACpB,mBAAO,IAAI,MAAM,CAAC,SAAS,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,CAAA;SAC1C;;;WAVC,MAAM;GAAS,KAAK;;AAa1B,IAAI,IAAI,GAAG,IAAI,SAAS,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;AAC5C,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AAClB,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;;AAE7B,IAAI,MAAM,GAAG,IAAI,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;AACrC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;AACpB,MAAM,CAAC,IAAI,CAAC,EAAE,EAAC,EAAE,CAAC,CAAC;AACnB,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;AACpB,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC","file":"04. classes and inheritance-compiled.js","sourcesContent":["// Definition\r\nclass Shape {\r\n constructor (id, x, y) {\r\n this.id = id;\r\n this.move(x, y);\r\n }\r\n move (x, y) {\r\n this.x = x;\r\n this.y = y;\r\n }\r\n toString () {\r\n return `Shape(${this.id})`;\r\n }\r\n}\r\n\r\n// Inheritance\r\nclass Rectangle extends Shape {\r\n constructor (id, x, y, width, height) {\r\n super(id, x, y);\r\n this.width = width;\r\n this.height = height;\r\n }\r\n toString () {\r\n return \"Rectangle > \" + super.toString();\r\n }\r\n static defaultRectangle () {\r\n return new Rectangle(\"default\", 0, 0, 100, 100)\r\n }\r\n}\r\n\r\nclass Circle extends Shape {\r\n constructor (id, x, y, radius) {\r\n super(id, x, y);\r\n this.radius = radius;\r\n }\r\n toString () {\r\n return \"Circle > \" + super.toString();\r\n }\r\n static defaultCircle () {\r\n return new Circle(\"default\", 0, 0, 100)\r\n }\r\n}\r\n\r\nlet rect = new Rectangle(1, 10, 20, 10, 20);\r\nconsole.log(rect);\r\nconsole.log(rect.toString());\r\n\r\nlet circle = new Circle(2, 0, 0, 10);\r\nconsole.log(circle);\r\ncircle.move(10,10);\r\nconsole.log(circle);\r\nconsole.log(circle.toString());"]} -------------------------------------------------------------------------------- /Topics/07. ES2015-Features/demos/04. classes and inheritance.js: -------------------------------------------------------------------------------- 1 | // Definition 2 | class Shape { 3 | constructor (id, x, y) { 4 | this.id = id; 5 | this.move(x, y); 6 | } 7 | move (x, y) { 8 | this.x = x; 9 | this.y = y; 10 | } 11 | toString () { 12 | return `Shape(${this.id})`; 13 | } 14 | } 15 | 16 | // Inheritance 17 | class Rectangle extends Shape { 18 | constructor (id, x, y, width, height) { 19 | super(id, x, y); 20 | this.width = width; 21 | this.height = height; 22 | } 23 | toString () { 24 | return "Rectangle > " + super.toString(); 25 | } 26 | static defaultRectangle () { 27 | return new Rectangle("default", 0, 0, 100, 100) 28 | } 29 | } 30 | 31 | class Circle extends Shape { 32 | constructor (id, x, y, radius) { 33 | super(id, x, y); 34 | this.radius = radius; 35 | } 36 | toString () { 37 | return "Circle > " + super.toString(); 38 | } 39 | static defaultCircle () { 40 | return new Circle("default", 0, 0, 100) 41 | } 42 | } 43 | 44 | let rect = new Rectangle(1, 10, 20, 10, 20); 45 | console.log(rect); 46 | console.log(rect.toString()); 47 | 48 | let circle = new Circle(2, 0, 0, 10); 49 | console.log(circle); 50 | circle.move(10,10); 51 | console.log(circle); 52 | console.log(circle.toString()); -------------------------------------------------------------------------------- /Topics/07. ES2015-Features/demos/05. arrow functions-compiled.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var evens = [2, 3, 5, 6, 1, 3]; 4 | 5 | // Expression bodies 6 | var odds = evens.map(function (v) { 7 | return v + 1; 8 | }); 9 | var nums = evens.map(function (v, i) { 10 | return v + i; 11 | }); 12 | 13 | // Statement bodies 14 | var fives = []; 15 | nums.forEach(function (v) { 16 | if (v % 5 === 0) { 17 | fives.push(v); 18 | } 19 | }); 20 | console.log(fives); 21 | 22 | // Lexical this 23 | var bob = { 24 | _name: 'Bob', 25 | _friends: ['Rob', 'Steve', 'John'], 26 | printFriends: function printFriends() { 27 | var _this = this; 28 | 29 | this._friends.forEach(function (f) { 30 | return console.log(_this._name + ' knows ' + f); 31 | }); 32 | } 33 | }; 34 | 35 | //# sourceMappingURL=05. arrow functions-compiled.js.map -------------------------------------------------------------------------------- /Topics/07. ES2015-Features/demos/05. arrow functions-compiled.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["05. arrow functions.js"],"names":[],"mappings":";;AACA,IAAI,KAAK,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;;;AAG/B,IAAI,IAAI,GAAG,KAAK,CAAC,GAAG,CAAC,UAAA,CAAC;WAAI,CAAC,GAAG,CAAC;CAAA,CAAC,CAAC;AACjC,IAAI,IAAI,GAAG,KAAK,CAAC,GAAG,CAAC,UAAC,CAAC,EAAE,CAAC;WAAK,CAAC,GAAG,CAAC;CAAA,CAAC,CAAC;;;AAGtC,IAAI,KAAK,GAAG,EAAE,CAAC;AACf,IAAI,CAAC,OAAO,CAAC,UAAA,CAAC,EAAI;AACd,QAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EACf;AACI,aAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KACjB;CACJ,CAAC,CAAC;AACH,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;;;AAGnB,IAAI,GAAG,GAAG;AACN,SAAK,EAAE,KAAK;AACZ,YAAQ,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,CAAC;AAClC,gBAAY,EAAA,wBAAG;;;AACX,YAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,UAAA,CAAC;mBACvB,OAAO,CAAC,GAAG,CAAC,MAAK,KAAK,GAAG,SAAS,GAAG,CAAC,CAAC;SAAA,CAAC,CAAC;KAC5C;CACJ,CAAA","file":"05. arrow functions-compiled.js","sourcesContent":["\r\nvar evens = [2, 3, 5, 6, 1, 3];\r\n\r\n// Expression bodies\r\nvar odds = evens.map(v => v + 1);\r\nvar nums = evens.map((v, i) => v + i);\r\n\r\n// Statement bodies\r\nvar fives = [];\r\nnums.forEach(v => {\r\n if (v % 5 === 0)\r\n {\r\n fives.push(v);\r\n }\r\n});\r\nconsole.log(fives);\r\n\r\n// Lexical this\r\nvar bob = {\r\n _name: 'Bob',\r\n _friends: ['Rob', 'Steve', 'John'],\r\n printFriends() {\r\n this._friends.forEach(f =>\r\n console.log(this._name + ' knows ' + f));\r\n }\r\n}"]} -------------------------------------------------------------------------------- /Topics/07. ES2015-Features/demos/05. arrow functions.js: -------------------------------------------------------------------------------- 1 | 2 | var evens = [2, 3, 5, 6, 1, 3]; 3 | 4 | // Expression bodies 5 | var odds = evens.map(v => v + 1); 6 | var nums = evens.map((v, i) => v + i); 7 | 8 | // Statement bodies 9 | var fives = []; 10 | nums.forEach(v => { 11 | if (v % 5 === 0) 12 | { 13 | fives.push(v); 14 | } 15 | }); 16 | console.log(fives); 17 | 18 | // Lexical this 19 | var bob = { 20 | _name: 'Bob', 21 | _friends: ['Rob', 'Steve', 'John'], 22 | printFriends() { 23 | this._friends.forEach(f => 24 | console.log(this._name + ' knows ' + f)); 25 | } 26 | } -------------------------------------------------------------------------------- /Topics/07. ES2015-Features/demos/06. destructuring assignments-compiled.js: -------------------------------------------------------------------------------- 1 | // array matching 2 | 'use strict'; 3 | 4 | var _slicedToArray = (function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i['return']) _i['return'](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError('Invalid attempt to destructure non-iterable instance'); } }; })(); 5 | 6 | var list = [1, 2, 3, 4, 5, 6]; 7 | var a = list[0]; 8 | var b = list[1]; 9 | var c = list.slice(2); 10 | 11 | //[ b, a ] = [ a, b ]; 12 | 13 | console.log('a = ' + a); 14 | console.log('b = ' + b); 15 | console.log('c = ' + c); 16 | 17 | // Object matching 18 | var _fname$lname$age = { 19 | fname: 'John', 20 | lname: 'Doe', 21 | age: 32 22 | }; 23 | var fname = _fname$lname$age.fname; 24 | var age = _fname$lname$age.age; 25 | var lname = _fname$lname$age.lname; 26 | 27 | console.log('first name: ' + fname); 28 | console.log('age: ' + age); 29 | 30 | // Deep object matching 31 | var _fname$lname$age$address = { 32 | fname: 'John', 33 | lname: 'Doe', 34 | age: 32, 35 | address: { city: 'Sofia' } 36 | }; 37 | var fname = _fname$lname$age$address.fname; 38 | var age = _fname$lname$age$address.age; 39 | var lname = _fname$lname$age$address.lname; 40 | var city = _fname$lname$age$address.address.city; 41 | 42 | console.log('first name: ' + fname); 43 | console.log('city: ' + city); 44 | 45 | // parameter context matching 46 | function f(_ref) { 47 | var _ref2 = _slicedToArray(_ref, 2); 48 | 49 | var name = _ref2[0]; 50 | var val = _ref2[1]; 51 | 52 | console.log(name, val); 53 | } 54 | function g(_ref3) { 55 | var n = _ref3.name; 56 | var v = _ref3.val; 57 | 58 | console.log(n, v); 59 | } 60 | function h(_ref4) { 61 | var name = _ref4.name; 62 | var val = _ref4.val; 63 | 64 | console.log(name, val); 65 | } 66 | f(['bar', 42]); 67 | g({ name: 'foo', val: 7 }); 68 | h({ name: 'bar', val: 42 }); 69 | 70 | // fail-soft destruction 71 | var list = [7, 42]; 72 | var _list$0 = list[0]; 73 | var a = _list$0 === undefined ? 1 : _list$0; 74 | var _list$1 = list[1]; 75 | var b = _list$1 === undefined ? 2 : _list$1; 76 | var _list$2 = list[2]; 77 | var c = _list$2 === undefined ? 3 : _list$2; 78 | var d = list[3]; 79 | 80 | console.log('a = ' + a); 81 | console.log('b = ' + b); 82 | console.log('c = ' + c); 83 | console.log('d = ' + d); 84 | 85 | //# sourceMappingURL=06. destructuring assignments-compiled.js.map -------------------------------------------------------------------------------- /Topics/07. ES2015-Features/demos/06. destructuring assignments-compiled.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["06. destructuring assignments.js"],"names":[],"mappings":";;;;;AACA,IAAI,IAAI,GAAG,CAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAE,CAAC;IAC1B,CAAC,GAAc,IAAI;IAAhB,CAAC,GAAW,IAAI;IAAV,CAAC,GAAK,IAAI;;;;AAGzB,OAAO,CAAC,GAAG,UAAQ,CAAC,CAAG,CAAC;AACxB,OAAO,CAAC,GAAG,UAAQ,CAAC,CAAG,CAAC;AACxB,OAAO,CAAC,GAAG,UAAQ,CAAC,CAAG,CAAC;;;uBAGI;AACxB,SAAK,EAAE,MAAM;AACb,SAAK,EAAC,KAAK;AACX,OAAG,EAAE,EAAE;CACV;IAJK,KAAK,oBAAL,KAAK;IAAE,GAAG,oBAAH,GAAG;IAAE,KAAK,oBAAL,KAAK;;AAMvB,OAAO,CAAC,GAAG,kBAAgB,KAAK,CAAG,CAAC;AACpC,OAAO,CAAC,GAAG,WAAS,GAAG,CAAG,CAAC;;;+BAGkB;AACzC,SAAK,EAAE,MAAM;AACb,SAAK,EAAC,KAAK;AACX,OAAG,EAAE,EAAE;AACP,WAAO,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE;CAC7B;IALK,KAAK,4BAAL,KAAK;IAAE,GAAG,4BAAH,GAAG;IAAE,KAAK,4BAAL,KAAK;IAAY,IAAI,4BAAd,OAAO,CAAG,IAAI;;AAOvC,OAAO,CAAC,GAAG,kBAAgB,KAAK,CAAG,CAAC;AACpC,OAAO,CAAC,GAAG,YAAU,IAAI,CAAG,CAAC;;;AAG7B,SAAS,CAAC,CAAE,IAAa,EAAE;+BAAf,IAAa;;QAAX,IAAI;QAAE,GAAG;;AACnB,WAAO,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,CAAA;CACzB;AACD,SAAS,CAAC,CAAE,KAAmB,EAAE;QAAb,CAAC,GAAT,KAAmB,CAAjB,IAAI;QAAU,CAAC,GAAjB,KAAmB,CAAR,GAAG;;AACtB,WAAO,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;CACpB;AACD,SAAS,CAAC,CAAE,KAAa,EAAE;QAAb,IAAI,GAAN,KAAa,CAAX,IAAI;QAAE,GAAG,GAAX,KAAa,CAAL,GAAG;;AACnB,WAAO,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,CAAA;CACzB;AACD,CAAC,CAAC,CAAE,KAAK,EAAE,EAAE,CAAE,CAAC,CAAA;AAChB,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,EAAG,CAAC,EAAE,CAAC,CAAA;AAC3B,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,CAAA;;;AAG3B,IAAI,IAAI,GAAG,CAAE,CAAC,EAAE,EAAE,CAAE,CAAA;cACa,IAAI;IAA/B,CAAC,2BAAG,CAAC;cAAsB,IAAI;IAAxB,CAAC,2BAAG,CAAC;cAAe,IAAI;IAAjB,CAAC,2BAAG,CAAC;IAAE,CAAC,GAAK,IAAI;;AACrC,OAAO,CAAC,GAAG,UAAQ,CAAC,CAAG,CAAC;AACxB,OAAO,CAAC,GAAG,UAAQ,CAAC,CAAG,CAAC;AACxB,OAAO,CAAC,GAAG,UAAQ,CAAC,CAAG,CAAC;AACxB,OAAO,CAAC,GAAG,UAAQ,CAAC,CAAG,CAAC","file":"06. destructuring assignments-compiled.js","sourcesContent":["// array matching\r\nvar list = [ 1, 2, 3, 4, 5, 6 ];\r\nvar [ a, b, ...c ] = list;\r\n//[ b, a ] = [ a, b ];\r\n\r\nconsole.log(`a = ${a}`);\r\nconsole.log(`b = ${b}`);\r\nconsole.log(`c = ${c}`);\r\n\r\n// Object matching\r\nvar { fname, age, lname } = {\r\n fname: 'John',\r\n lname:'Doe',\r\n age: 32\r\n};\r\n\r\nconsole.log(`first name: ${fname}`);\r\nconsole.log(`age: ${age}`);\r\n\r\n// Deep object matching\r\nvar { fname, age, lname, address: {city} } = {\r\n fname: 'John',\r\n lname:'Doe',\r\n age: 32,\r\n address: { city: 'Sofia' }\r\n};\r\n\r\nconsole.log(`first name: ${fname}`);\r\nconsole.log(`city: ${city}`);\r\n\r\n// parameter context matching\r\nfunction f ([ name, val ]) {\r\n console.log(name, val)\r\n}\r\nfunction g ({ name: n, val: v }) {\r\n console.log(n, v)\r\n}\r\nfunction h ({ name, val }) {\r\n console.log(name, val)\r\n}\r\nf([ \"bar\", 42 ])\r\ng({ name: \"foo\", val: 7 })\r\nh({ name: \"bar\", val: 42 })\r\n\r\n// fail-soft destruction\r\nvar list = [ 7, 42 ]\r\nvar [ a = 1, b = 2, c = 3, d ] = list\r\nconsole.log(`a = ${a}`);\r\nconsole.log(`b = ${b}`);\r\nconsole.log(`c = ${c}`);\r\nconsole.log(`d = ${d}`);\r\n"]} -------------------------------------------------------------------------------- /Topics/07. ES2015-Features/demos/06. destructuring assignments.js: -------------------------------------------------------------------------------- 1 | // array matching 2 | var list = [ 1, 2, 3, 4, 5, 6 ]; 3 | var [ a, b, ...c ] = list; 4 | //[ b, a ] = [ a, b ]; 5 | 6 | console.log(`a = ${a}`); 7 | console.log(`b = ${b}`); 8 | console.log(`c = ${c}`); 9 | 10 | // Object matching 11 | var { fname, age, lname } = { 12 | fname: 'John', 13 | lname:'Doe', 14 | age: 32 15 | }; 16 | 17 | console.log(`first name: ${fname}`); 18 | console.log(`age: ${age}`); 19 | 20 | // Deep object matching 21 | var { fname, age, lname, address: {city} } = { 22 | fname: 'John', 23 | lname:'Doe', 24 | age: 32, 25 | address: { city: 'Sofia' } 26 | }; 27 | 28 | console.log(`first name: ${fname}`); 29 | console.log(`city: ${city}`); 30 | 31 | // parameter context matching 32 | function f ([ name, val ]) { 33 | console.log(name, val) 34 | } 35 | function g ({ name: n, val: v }) { 36 | console.log(n, v) 37 | } 38 | function h ({ name, val }) { 39 | console.log(name, val) 40 | } 41 | f([ "bar", 42 ]) 42 | g({ name: "foo", val: 7 }) 43 | h({ name: "bar", val: 42 }) 44 | 45 | // fail-soft destruction 46 | var list = [ 7, 42 ] 47 | var [ a = 1, b = 2, c = 3, d ] = list 48 | console.log(`a = ${a}`); 49 | console.log(`b = ${b}`); 50 | console.log(`c = ${c}`); 51 | console.log(`d = ${d}`); 52 | -------------------------------------------------------------------------------- /Topics/07. ES2015-Features/demos/07. maps and sets-compiled.js: -------------------------------------------------------------------------------- 1 | // set 2 | 'use strict'; 3 | 4 | var _slicedToArray = (function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i['return']) _i['return'](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError('Invalid attempt to destructure non-iterable instance'); } }; })(); 5 | 6 | var s = new Set(); 7 | s.add('hello').add('goodbye').add('hello'); 8 | 9 | console.log('s.size = ' + s.size); 10 | console.log('s.has(\'hello\') = ' + s.has('hello')); 11 | var _iteratorNormalCompletion = true; 12 | var _didIteratorError = false; 13 | var _iteratorError = undefined; 14 | 15 | try { 16 | for (var _iterator = s.values()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { 17 | var key = _step.value; 18 | // insertion order 19 | console.log(key); 20 | } 21 | } catch (err) { 22 | _didIteratorError = true; 23 | _iteratorError = err; 24 | } finally { 25 | try { 26 | if (!_iteratorNormalCompletion && _iterator['return']) { 27 | _iterator['return'](); 28 | } 29 | } finally { 30 | if (_didIteratorError) { 31 | throw _iteratorError; 32 | } 33 | } 34 | } 35 | 36 | // map 37 | var m = new Map(); 38 | m.set('hello', 42); 39 | m.set(s, 34); 40 | console.log('m.get(s) = ' + m.get(s)); 41 | console.log('m.get(s) = ' + m.get('hello')); 42 | console.log('m.size = ' + m.size); 43 | var _iteratorNormalCompletion2 = true; 44 | var _didIteratorError2 = false; 45 | var _iteratorError2 = undefined; 46 | 47 | try { 48 | for (var _iterator2 = m.entries()[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { 49 | var _step2$value = _slicedToArray(_step2.value, 2); 50 | 51 | var key = _step2$value[0]; 52 | var val = _step2$value[1]; 53 | 54 | console.log(key + ' = ' + val); 55 | } 56 | } catch (err) { 57 | _didIteratorError2 = true; 58 | _iteratorError2 = err; 59 | } finally { 60 | try { 61 | if (!_iteratorNormalCompletion2 && _iterator2['return']) { 62 | _iterator2['return'](); 63 | } 64 | } finally { 65 | if (_didIteratorError2) { 66 | throw _iteratorError2; 67 | } 68 | } 69 | } 70 | 71 | //# sourceMappingURL=07. maps and sets-compiled.js.map -------------------------------------------------------------------------------- /Topics/07. ES2015-Features/demos/07. maps and sets-compiled.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["07. maps and sets.js"],"names":[],"mappings":";;;;;AACA,IAAI,CAAC,GAAG,IAAI,GAAG,EAAE,CAAC;AAClB,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CACT,GAAG,CAAC,SAAS,CAAC,CACd,GAAG,CAAC,OAAO,CAAC,CAAC;;AAElB,OAAO,CAAC,GAAG,eAAa,CAAC,CAAC,IAAI,CAAG,CAAC;AAClC,OAAO,CAAC,GAAG,yBAAqB,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAG,CAAC;;;;;;AAClD,yBAAgB,CAAC,CAAC,MAAM,EAAE,8HAC1B;YADS,GAAG;;AAER,eAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;KACpB;;;;;;;;;;;;;;;;;AAGD,IAAI,CAAC,GAAG,IAAI,GAAG,EAAE,CAAC;AAClB,CAAC,CAAC,GAAG,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;AACnB,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AACb,OAAO,CAAC,GAAG,iBAAe,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAG,CAAC;AACtC,OAAO,CAAC,GAAG,iBAAe,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAG,CAAC;AAC5C,OAAO,CAAC,GAAG,eAAa,CAAC,CAAC,IAAI,CAAG,CAAC;;;;;;AAClC,0BAAyB,CAAC,CAAC,OAAO,EAAE,mIAAE;;;YAA3B,GAAG;YAAE,GAAG;;AACf,eAAO,CAAC,GAAG,CAAC,GAAG,GAAG,KAAK,GAAG,GAAG,CAAC,CAAC;KAClC","file":"07. maps and sets-compiled.js","sourcesContent":["// set\r\nlet s = new Set();\r\ns.add('hello')\r\n .add('goodbye')\r\n .add('hello');\r\n\r\nconsole.log(`s.size = ${s.size}`);\r\nconsole.log(`s.has('hello') = ${s.has(\"hello\")}`);\r\nfor (let key of s.values())\r\n{ // insertion order\r\n console.log(key);\r\n}\r\n\r\n// map\r\nlet m = new Map();\r\nm.set('hello', 42);\r\nm.set(s, 34);\r\nconsole.log(`m.get(s) = ${m.get(s)}`);\r\nconsole.log(`m.get(s) = ${m.get('hello')}`);\r\nconsole.log(`m.size = ${m.size}`);\r\nfor (let [ key, val ] of m.entries()) {\r\n console.log(key + \" = \" + val);\r\n}"]} -------------------------------------------------------------------------------- /Topics/07. ES2015-Features/demos/07. maps and sets.js: -------------------------------------------------------------------------------- 1 | // set 2 | let s = new Set(); 3 | s.add('hello') 4 | .add('goodbye') 5 | .add('hello'); 6 | 7 | console.log(`s.size = ${s.size}`); 8 | console.log(`s.has('hello') = ${s.has("hello")}`); 9 | for (let key of s.values()) 10 | { // insertion order 11 | console.log(key); 12 | } 13 | 14 | // map 15 | let m = new Map(); 16 | m.set('hello', 42); 17 | m.set(s, 34); 18 | console.log(`m.get(s) = ${m.get(s)}`); 19 | console.log(`m.get(s) = ${m.get('hello')}`); 20 | console.log(`m.size = ${m.size}`); 21 | for (let [ key, val ] of m.entries()) { 22 | console.log(key + " = " + val); 23 | } -------------------------------------------------------------------------------- /Topics/07. ES2015-Features/demos/09. extended parameter handling-compiled.js: -------------------------------------------------------------------------------- 1 | // extended parameter values 2 | "use strict"; 3 | 4 | function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; return arr2; } else { return Array.from(arr); } } 5 | 6 | function f1(x) { 7 | var y = arguments[1] === undefined ? 7 : arguments[1]; 8 | var z = arguments[2] === undefined ? 42 : arguments[2]; 9 | 10 | return x + y + z; 11 | } 12 | console.log(f1(1)); // 50 13 | 14 | // rest parameter 15 | function f2(x, y) { 16 | for (var _len = arguments.length, a = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) { 17 | a[_key - 2] = arguments[_key]; 18 | } 19 | 20 | return (x + y) * a.length; 21 | } 22 | console.log(f2(1, 2, "hello", true, 7)); // 9 23 | 24 | // spread operator 25 | var params = ["hello", true, 7]; 26 | var other = [1, 2].concat(params); // [ 1, 2, "hello", true, 7 ] 27 | console.log(f2.apply(undefined, [1, 2].concat(params))); // 9 28 | 29 | var str = "foo"; 30 | var chars = [].concat(_toConsumableArray(str)); // [ "f", "o", "o" ] 31 | console.log(chars); 32 | 33 | //# sourceMappingURL=09. extended parameter handling-compiled.js.map -------------------------------------------------------------------------------- /Topics/07. ES2015-Features/demos/09. extended parameter handling-compiled.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["09. extended parameter handling.js"],"names":[],"mappings":";;;;;AACA,SAAS,EAAE,CAAE,CAAC,EAAiB;QAAf,CAAC,gCAAG,CAAC;QAAE,CAAC,gCAAG,EAAE;;AACzB,WAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;CACnB;AACD,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;;;AAGnB,SAAS,EAAE,CAAE,CAAC,EAAE,CAAC,EAAQ;sCAAH,CAAC;AAAD,SAAC;;;AACnB,WAAO,CAAC,CAAC,GAAG,CAAC,CAAA,GAAI,CAAC,CAAC,MAAM,CAAC;CAC7B;AACD,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;;;AAGxC,IAAI,MAAM,GAAG,CAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAE,CAAA;AACjC,IAAI,KAAK,IAAK,CAAC,EAAE,CAAC,SAAK,MAAM,CAAE,CAAA;AAC/B,OAAO,CAAC,GAAG,CAAC,EAAE,mBAAC,CAAC,EAAE,CAAC,SAAK,MAAM,EAAC,CAAC,CAAC;;AAEjC,IAAI,GAAG,GAAG,KAAK,CAAA;AACf,IAAI,KAAK,gCAAQ,GAAG,EAAE,CAAA;AACtB,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC","file":"09. extended parameter handling-compiled.js","sourcesContent":["// extended parameter values\r\nfunction f1 (x, y = 7, z = 42) {\r\n return x + y + z\r\n}\r\nconsole.log(f1(1)); // 50\r\n\r\n// rest parameter\r\nfunction f2 (x, y, ...a) {\r\n return (x + y) * a.length;\r\n}\r\nconsole.log(f2(1, 2, \"hello\", true, 7)); // 9\r\n\r\n// spread operator\r\nvar params = [ \"hello\", true, 7 ]\r\nvar other = [ 1, 2, ...params ] // [ 1, 2, \"hello\", true, 7 ]\r\nconsole.log(f2(1, 2, ...params)); // 9\r\n\r\nvar str = \"foo\"\r\nvar chars = [ ...str ] // [ \"f\", \"o\", \"o\" ]\r\nconsole.log(chars);"]} -------------------------------------------------------------------------------- /Topics/07. ES2015-Features/demos/09. extended parameter handling.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TelerikAcademy/JavaScript-OOP/759390f2476ff639e41be6d585ae3c458d41efb3/Topics/07. ES2015-Features/demos/09. extended parameter handling.js -------------------------------------------------------------------------------- /Topics/07. ES2015-Features/demos/10. Symbol type-compiled.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | Symbol("foo") !== Symbol("foo"); 4 | var foo = Symbol(); 5 | var bar = Symbol(); 6 | typeof foo === "symbol"; 7 | typeof bar === "symbol"; 8 | var obj = {}; 9 | obj[foo] = "foo"; 10 | obj[bar] = "bar"; 11 | JSON.stringify(obj); // {} 12 | Object.keys(obj); // [] 13 | Object.getOwnPropertyNames(obj); // [] 14 | Object.getOwnPropertySymbols(obj); // [ foo, bar ] 15 | 16 | //# sourceMappingURL=10. Symbol type-compiled.js.map -------------------------------------------------------------------------------- /Topics/07. ES2015-Features/demos/10. Symbol type-compiled.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["10. Symbol type.js"],"names":[],"mappings":";;AAAA,MAAM,CAAC,KAAK,CAAC,KAAK,MAAM,CAAC,KAAK,CAAC,CAAA;AAC/B,IAAM,GAAG,GAAG,MAAM,EAAE,CAAA;AACpB,IAAM,GAAG,GAAG,MAAM,EAAE,CAAA;AACpB,OAAO,GAAG,KAAK,QAAQ,CAAA;AACvB,OAAO,GAAG,KAAK,QAAQ,CAAA;AACvB,IAAI,GAAG,GAAG,EAAE,CAAA;AACZ,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAA;AAChB,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAA;AAChB,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAA;AACnB,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AAChB,MAAM,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAA;AAC/B,MAAM,CAAC,qBAAqB,CAAC,GAAG,CAAC,CAAA","file":"10. Symbol type-compiled.js","sourcesContent":["Symbol(\"foo\") !== Symbol(\"foo\")\r\nconst foo = Symbol()\r\nconst bar = Symbol()\r\ntypeof foo === \"symbol\"\r\ntypeof bar === \"symbol\"\r\nlet obj = {}\r\nobj[foo] = \"foo\"\r\nobj[bar] = \"bar\"\r\nJSON.stringify(obj) // {}\r\nObject.keys(obj) // []\r\nObject.getOwnPropertyNames(obj) // []\r\nObject.getOwnPropertySymbols(obj) // [ foo, bar ]"]} -------------------------------------------------------------------------------- /Topics/07. ES2015-Features/demos/10. Symbol type.js: -------------------------------------------------------------------------------- 1 | Symbol("foo") !== Symbol("foo") 2 | const foo = Symbol() 3 | const bar = Symbol() 4 | typeof foo === "symbol" 5 | typeof bar === "symbol" 6 | let obj = {} 7 | obj[foo] = "foo" 8 | obj[bar] = "bar" 9 | JSON.stringify(obj) // {} 10 | Object.keys(obj) // [] 11 | Object.getOwnPropertyNames(obj) // [] 12 | Object.getOwnPropertySymbols(obj) // [ foo, bar ] -------------------------------------------------------------------------------- /Topics/07. ES2015-Features/demos/live-demos/features-Symbol-and-iterators.js: -------------------------------------------------------------------------------- 1 | /* globals console setTimeout document */ 2 | 3 | 4 | // class DataStorage { 5 | // constructor() { 6 | // this._items = []; 7 | // } 8 | 9 | // add(item) { 10 | // this._items.push(item); 11 | // return this; 12 | // } 13 | 14 | // [Symbol.iterator]() { 15 | // let index = -1; 16 | // return { 17 | // next: () => { 18 | // index += 1; 19 | // let isDone = false; 20 | // if (index >= this._items.length) { 21 | // isDone = true; 22 | // } 23 | 24 | // return { 25 | // value: this._items[index], 26 | // done: isDone 27 | // }; 28 | // } 29 | // }; 30 | // } 31 | // } 32 | 33 | // let ds = new DataStorage(); 34 | // ds.add(3); 35 | // ds.add(1); 36 | // ds.add(2); 37 | // ds.add(999); 38 | 39 | // for (let item of ds) { 40 | // console.log(item); 41 | // } 42 | 43 | 44 | 45 | let fib = { 46 | [Symbol.iterator]() { 47 | let prev = 1, 48 | current = 0; 49 | 50 | return { 51 | next() { 52 | let valueToReturn = { 53 | value: current, 54 | done: false 55 | }; 56 | [prev, current] = [current, prev + current]; 57 | return valueToReturn; 58 | } 59 | }; 60 | } 61 | }; 62 | 63 | let index = 0; 64 | 65 | for (let fn of fib) { 66 | if (index >= 100) { 67 | break; 68 | } 69 | index += 1; 70 | 71 | console.log(fn); 72 | } -------------------------------------------------------------------------------- /Topics/07. ES2015-Features/demos/live-demos/features-destructuring.js: -------------------------------------------------------------------------------- 1 | /* globals console setTimeout document */ 2 | 3 | // let arr = [1, 2, 3]; 4 | 5 | // let one = "One", 6 | // two = "Two"; 7 | 8 | // let [first, second] = [one, two]; 9 | // console.log(first); 10 | // console.log(second); 11 | 12 | 13 | // function getMinMax(numbers) { 14 | // return [Math.min(...numbers), Math.max(...numbers)]; 15 | // } 16 | 17 | 18 | // let [min, max] = getMinMax([1, 2, 3, -1, 1000, 5, -3]); 19 | // console.log(min); 20 | // console.log(max); 21 | 22 | 23 | // let cat = { 24 | // name: "Puhcho", 25 | // age: 7, 26 | // owner: { 27 | // name: "John", 28 | // height: 180 29 | // } 30 | // }; 31 | 32 | // let name = cat.name; 33 | 34 | // var { 35 | // age, 36 | // name: nickname, 37 | // owner: { name } 38 | // } = cat; 39 | // console.log(name); 40 | // console.log(nickname); 41 | // console.log(age); 42 | 43 | 44 | // let arr = [1, 2, 3, 4, 5, 6]; 45 | 46 | // let [x, y, ...rest] = arr; 47 | // console.log(x); 48 | // console.log(y); 49 | // console.log(rest); -------------------------------------------------------------------------------- /Topics/07. ES2015-Features/demos/live-demos/features-events.js: -------------------------------------------------------------------------------- 1 | /* globals console setTimeout document */ 2 | 3 | document.getElementById("declation-btn") 4 | .addEventListener("click", (function(ev) { 5 | console.log(this); 6 | }).bind(this)); 7 | 8 | 9 | //this 10 | document.getElementById("arrow-btn") 11 | .addEventListener("click", (ev) => { 12 | console.log(this); 13 | }); -------------------------------------------------------------------------------- /Topics/07. ES2015-Features/demos/live-demos/features-features-arrays.js: -------------------------------------------------------------------------------- 1 | /* globals console setTimeout document */ 2 | 3 | let a1 = [1, 2]; 4 | let a2 = Array.from({ length: 5 }); 5 | console.log(a2); 6 | 7 | console.log(Array.of(4, 6, 7, 8)); 8 | 9 | 10 | //spread (...) 11 | 12 | function sum(x, y, z) { 13 | return x + y + z; 14 | } 15 | 16 | let xyz = [1, 2, 3]; 17 | console.log(sum(...xyz)); 18 | console.log(xyz); 19 | // xyz.push(4); 20 | xyz = [0, ...xyz, 4]; 21 | console.log(xyz); -------------------------------------------------------------------------------- /Topics/07. ES2015-Features/demos/live-demos/features-function-params.js: -------------------------------------------------------------------------------- 1 | /* globals console setTimeout document */ 2 | 3 | //default params 4 | //rest params 5 | 6 | 7 | // function getRandom(min = 0, max = 50) { 8 | // return 0 | (Math.random() * (max - min) + min); 9 | // } 10 | 11 | // console.log(getRandom(100, 110)); 12 | // console.log(getRandom(45)); 13 | // console.log(getRandom()); 14 | 15 | 16 | // function getMinMax(...numbers) { 17 | // return { 18 | // min: Math.min(...numbers), 19 | // max: Math.max(...numbers) 20 | // }; 21 | // } 22 | 23 | // let { min, max } = getMinMax(1, 2, 3, 4, 5, 6, 7); 24 | 25 | // console.log(min); 26 | // console.log(max); -------------------------------------------------------------------------------- /Topics/07. ES2015-Features/demos/live-demos/features-generators.js: -------------------------------------------------------------------------------- 1 | /* globals console setTimeout document */ 2 | 3 | 4 | function* idGenerator() { 5 | let lastId = 0; 6 | while (true) { 7 | yield lastId += 1; 8 | } 9 | } 10 | 11 | 12 | // let idGen1 = idGenerator(); 13 | // let idGen2 = idGenerator(); 14 | 15 | // console.log(idGen1.next()); 16 | // console.log(idGen1.next()); 17 | // console.log(idGen1.next()); 18 | 19 | // console.log(idGen2.next()); 20 | 21 | 22 | // function* fibGenerator() { 23 | // let prev = 1, 24 | // current = 0; 25 | 26 | // while (true) { 27 | // yield current; 28 | // [prev, current] = [current, prev + current]; 29 | // } 30 | // } 31 | 32 | // let fib = fibGenerator(); 33 | // let fib2 = fibGenerator(); 34 | 35 | // for (let i = 0; i < 5; i += 1) { 36 | // console.log(fib.next()); 37 | // console.log(fib2.next()); 38 | // } 39 | 40 | // let index = 0; 41 | // for (let fibNumber of fibGenerator()) { 42 | // if (index > 10) { 43 | // break; 44 | // } 45 | // console.log(fibNumber); 46 | // index += 1; 47 | // } 48 | 49 | 50 | function* genFunc() { 51 | let name = "[INITIAL]"; 52 | let name2 = ""; 53 | while (true) { 54 | name = yield name 55 | } 56 | } 57 | 58 | let f = genFunc(); 59 | 60 | f.next(); 61 | 62 | console.log(f.next(["John", "Gosho"])); 63 | console.log(f.next("Doe")); 64 | console.log(f.next("Doe2")); -------------------------------------------------------------------------------- /Topics/07. ES2015-Features/demos/live-demos/features-numbers.js: -------------------------------------------------------------------------------- 1 | /* globals console setTimeout document */ 2 | 3 | 4 | let dec = 123, 5 | hex = 0x123, //1*16^2 + 2* 16 + 3 = 256 + 32 + 3 = 291 6 | oct = 0o123, //1*8^2 + 2*8 + 3 = 83 7 | bin = 0b1010; // 12 8 | 9 | console.log(`Dec: ${dec}`); 10 | console.log(`Hex: ${hex}`); 11 | console.log(`Oct: ${oct}`); 12 | console.log(`Bin: ${bin}`); -------------------------------------------------------------------------------- /Topics/07. ES2015-Features/demos/live-demos/features-objects.js: -------------------------------------------------------------------------------- 1 | /* globals console setTimeout document */ 2 | 3 | 4 | // let person = { 5 | // [(() => "name")()]: "John" 6 | // }; 7 | 8 | // console.log(person); 9 | 10 | 11 | // let obj1 = { 12 | // name: "John" 13 | // }; 14 | 15 | // let obj2 = Object.assign({ age: 17, name: "Pesho" }, obj1); 16 | // console.log(obj2); -------------------------------------------------------------------------------- /Topics/07. ES2015-Features/demos/live-demos/features-promises.js: -------------------------------------------------------------------------------- 1 | /* globals console setTimeout document */ 2 | 3 | const selector = "printing-div", 4 | printerDiv = document.getElementById(selector); 5 | 6 | let asyncOperations = { 7 | asyncOperation(t) { 8 | setTimeout(function() { 9 | printerDiv.innerHTML += "

It works

"; 10 | }, t); 11 | }, 12 | asyncOperationFunc(func, t) { 13 | setTimeout(function() { 14 | func(); 15 | }, t); 16 | }, 17 | asyncOperationFuncPromise(t) { 18 | let promise = new Promise(function(resolve) { 19 | setTimeout(function() { 20 | resolve(); 21 | }, t); 22 | }); 23 | return promise; 24 | } 25 | }; 26 | 27 | asyncOperations.asyncOperationFuncPromise(1000) 28 | .then(function() { 29 | printerDiv.innerHTML += "

1. It works with Promise

"; 30 | return asyncOperations.asyncOperationFuncPromise(1000) 31 | }) 32 | .then(function() { 33 | printerDiv.innerHTML += "

2. It works with Promise

"; 34 | return asyncOperations.asyncOperationFuncPromise(1000) 35 | }) 36 | .then(function() { 37 | printerDiv.innerHTML += "

3. It works with Promise

"; 38 | return asyncOperations.asyncOperationFuncPromise(2500) 39 | }) 40 | .then(function() { 41 | printerDiv.innerHTML += "

4. It works with Promise

"; 42 | return asyncOperations.asyncOperationFuncPromise(1000) 43 | }) 44 | .then(function() { 45 | printerDiv.innerHTML += "

5. It works with Promise

"; 46 | return asyncOperations.asyncOperationFuncPromise(1000) 47 | }) 48 | .then(function() { 49 | printerDiv.innerHTML += "

6. It works with Promise

"; 50 | return asyncOperations.asyncOperationFuncPromise(1000) 51 | }); 52 | 53 | // asyncOperations.asyncOperationFunc(function() { 54 | // printerDiv.innerHTML += "

1. It works

"; 55 | // asyncOperations.asyncOperationFunc(function() { 56 | // printerDiv.innerHTML += "

2. It works

"; 57 | // asyncOperations.asyncOperationFunc(function() { 58 | // printerDiv.innerHTML += "

3. It works

"; 59 | // asyncOperations.asyncOperationFunc(function() { 60 | // printerDiv.innerHTML += "

4. It works

"; 61 | // asyncOperations.asyncOperationFunc(function() { 62 | // printerDiv.innerHTML += "

5. It works

"; 63 | // asyncOperations.asyncOperationFunc(function() { 64 | // printerDiv.innerHTML += "

6. It works

"; 65 | // }, 1000); 66 | // }, 1000); 67 | // }, 1000); 68 | // }, 2000); 69 | // }, 1000); 70 | // }, 1000); 71 | -------------------------------------------------------------------------------- /Topics/07. ES2015-Features/demos/live-demos/features-strings.js: -------------------------------------------------------------------------------- 1 | /* globals console setTimeout document */ 2 | 3 | //templated string, string literals, multiline strings 4 | 5 | let fullname = "John Doe"; 6 | 7 | console.log(fullname.startsWith("John")); 8 | console.log(fullname.indexOf("John") === 0); 9 | 10 | console.log(fullname.endsWith("John")); 11 | console.log(fullname.endsWith("Doe")); 12 | console.log(fullname.indexOf("Doe") === (fullname.length - "Doe".length)); 13 | 14 | console.log("-".repeat(20)); 15 | console.log(fullname.includes("John")); 16 | console.log(fullname.includes("john")); 17 | console.log(fullname.includes("n D")); 18 | console.log(fullname.includes("Doe")); 19 | console.log(fullname.indexOf("Doe") >= 0); -------------------------------------------------------------------------------- /Topics/07. ES2015-Features/demos/live-demos/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Document 7 | 8 | 9 | 10 | Click 11 | Click 12 |
13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /Topics/07. ES2015-Features/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | EcmaScript2015 Features 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 26 | 27 | 28 | 29 |
30 |
31 |
32 | 33 | 34 | 35 | 36 | 37 | 38 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /Workshops/21-February-2017/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "test-driven-hw-mocha", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "mocha -R spec tests" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "devDependencies": { 12 | "chai": "^3.0.0", 13 | "mocha": "^3.0.2" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Workshops/21-February-2017/tasks/task-1.js: -------------------------------------------------------------------------------- 1 | function solve() { 2 | const module = { 3 | getPlayer: function (name){ 4 | // returns a new player instance with the provided name 5 | }, 6 | getPlaylist: function(name){ 7 | //returns a new playlist instance with the provided name 8 | }, 9 | getAudio: function(title, author, length){ 10 | //returns a new audio instance with the provided title, author and length 11 | }, 12 | getVideo: function(title, author, imdbRating){ 13 | //returns a new video instance with the provided title, author and imdbRating 14 | } 15 | }; 16 | 17 | return module; 18 | } 19 | 20 | module.exports = solve; 21 | -------------------------------------------------------------------------------- /Workshops/31-January-2017/README.md: -------------------------------------------------------------------------------- 1 | # Carts and Products 2 | 3 | - Implement a functionality to serve a Shopping Center 4 | - Export a function named **`getProduct`** 5 | - **Parameters** 6 | - `productType` 7 | - `name` 8 | - `price` 9 | - _Example_: 10 | - `getProduct("Sweets", "Shokolad Milka", 2)` 11 | - **Returns an object that contains**: 12 | - `productType`: `String` 13 | - `name`: `String` 14 | - `price`: `Number` 15 | - Export a function named **`getShoppingCart`** 16 | - **No parameters** 17 | - _Example_: 18 | - `getShoppingCart()` 19 | - **Returns an object that contains**: 20 | - `products`: `Array` 21 | - `add`: `Function` 22 | - `remove`: `Function` 23 | - `showCost`: `Function` 24 | - `showProductTypes`: `Function` 25 | - `getInfo`: `Function` 26 | 27 | ## Behavior of the `ShoppingCart` object methods 28 | 29 | - `add(product)` 30 | - **Parameters**: 31 | - A `Product` or Product-like object 32 | - **Behavior**: 33 | - Adds the `product` to the `products` array in the `ShoppingCart` instance 34 | - A product can be added many times into the same `ShoppingCart` instance 35 | - **Should provide chaining** 36 | - `remove(product)` 37 | - **Parameters** 38 | - a `Product` or Product-like object 39 | - **Behavior**: 40 | - Removes the left-most object from the `products` array in the `ShoppingCart` instance, that has the same `name`, `price` and `productType` 41 | - **Should provide chaining** 42 | - **Throws** when: 43 | - The `ShoppingCart` instance does not contain the product 44 | - There are not products in the `ShoppingCart` instance 45 | - `showCost()` 46 | - **No parameters** 47 | - **Behavior**: 48 | - Returns the sum from the costs of all products in the `ShoppingCart` instance 49 | - Returns `0` when there are no products in the `ShoppingCart` instance 50 | - `showProductTypes()` 51 | - **No parameters** 52 | - **Behavior**: 53 | - Returns the **unique productTypes** of the products added to the `ShoppingCart` instance 54 | - The returned product types must be **sorted alphabetically** 55 | - Returns an empty array when there are no products in the `ShoppingCart` instance 56 | - `getInfo()` 57 | - **No parameters** 58 | - **Behavior**: 59 | - Returns an object containing information about the products in the `ShoppingCart` instance. The returned object has two properties: 60 | - `products`: Groups products by their name 61 | - For each unique product name there creates an element: 62 | - The `name` of the products 63 | - Their total cost 64 | - The quantity of products with the name in the `ShoppingCart` instance 65 | - The groups must be **sorted alphabetically** by name 66 | - `totalPrice`: The total price of all products in the `ShoppingCart` instance 67 | - Returns an object with `totalPrice` equal to `0` and `products` - an empty array, when no products in the `ShoppingCart` instance 68 | 69 | ## Solution template 70 | 71 | ```javascript 72 | function solve() { 73 | function getProduct(productType, name, price) { 74 | } 75 | 76 | function getShoppingCart() { 77 | } 78 | 79 | return { 80 | getProduct: getProduct, 81 | getShoppingCart: getShoppingCart 82 | }; 83 | } 84 | 85 | module.exports = solve(); 86 | ``` 87 | 88 | ## Example usage: 89 | 90 | ```javascript 91 | const {getProduct, getShoppingCart} = solve(); 92 | 93 | let cart = getShoppingCart(); 94 | 95 | let pr1 = getProduct("Sweets", "Shokolad Milka", 2); 96 | cart.add(pr1); 97 | console.log(cart.showCost()); 98 | // prints `2` 99 | 100 | let pr2 = getProduct("Groceries", "Salad", 0.5); 101 | cart.add(pr2); 102 | cart.add(pr2); 103 | console.log(cart.showCost()); 104 | // prints `3` 105 | 106 | console.log(cart.showProductTypes()); 107 | // prints [ 'Groceries', 'Sweets' ] 108 | 109 | console.log(cart.getInfo()); 110 | /* prints 111 | { 112 | totalPrice: 3 113 | products: [{ 114 | name: "Salad", 115 | totalPrice: 1, 116 | quantity: 2 117 | }, { 118 | name: "Shokolad Milka", 119 | totalPrice: 2, 120 | quantity: 1 121 | }] 122 | } 123 | */ 124 | 125 | cart.remove({name:"salad", productType: "Groceries", price: 0.5}) 126 | // throws: "salad" is not equal to "Salad" 127 | 128 | cart.remove({name:"Salad", productType: "Groceries", price: 0.5}) 129 | console.log(cart.getInfo()); 130 | /* prints 131 | { 132 | totalPrice: 2.5 133 | products: [{ 134 | name: "Salad", 135 | totalPrice: 0.5, 136 | quantity: 1 137 | }, { 138 | name: "Shokolad Milka", 139 | totalPrice: 2, 140 | quantity: 1 141 | }] 142 | } 143 | */ 144 | ``` 145 | -------------------------------------------------------------------------------- /Workshops/31-January-2017/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "test-driven-hw-mocha", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "mocha -R spec ./tests" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "devDependencies": { 12 | "chai": "^3.5.0", 13 | "mocha": "^3.2.0" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Workshops/31-January-2017/task/solution.js: -------------------------------------------------------------------------------- 1 | function solve() { 2 | function getProduct(productType, name, price) { 3 | // validations 4 | return { 5 | productType: productType, 6 | name: name, 7 | price: price 8 | }; 9 | } 10 | 11 | function getShoppingCart() { 12 | const products = []; 13 | 14 | function add(product) { 15 | products.push(product); 16 | return this; 17 | } 18 | 19 | function remove(product) { 20 | const index = products.findIndex(p => p.name === product.name && p.productType === product.productType && p.price === product.price); 21 | 22 | if(index < 0) { 23 | throw 'Product not found'; 24 | } 25 | 26 | products.splice(index, 1); 27 | 28 | return this; 29 | } 30 | 31 | function showCost() { 32 | return products.reduce((cost, product) => cost + product.price, 0); 33 | } 34 | 35 | function showProductTypes() { 36 | /*const uniqTypes = []; 37 | products.forEach(function(p) { 38 | if(uniqTypes.indexOf(p.productType) < 0) { 39 | uniqTypes.push(p.productType); 40 | } 41 | }); 42 | 43 | return uniqTypes.sort();*/ 44 | 45 | /* 46 | return products.map(p => p.productType) 47 | .sort() 48 | .filter((p, i, ps) => i === 0 || p !== ps[i - 1]); 49 | */ 50 | 51 | const uniqTypesObj = {}; 52 | products.forEach(p => uniqTypesObj[p.productType] = true); 53 | return Object.keys(uniqTypesObj).sort(); 54 | } 55 | 56 | function getInfo() { 57 | /* 58 | const uniqNames = products.map(p => p.name) 59 | .sort() 60 | .filter((p, i, ps) => i === 0 || p !== ps[i - 1]) 61 | .map(name => { 62 | const withThisName = products.filter(p => p.name === name); 63 | 64 | return { 65 | name: name, 66 | quantity: withThisName.length, 67 | totalPrice: withThisName.reduce((cost, product) => cost + product.price, 0) 68 | }; 69 | }); 70 | 71 | return { 72 | products: uniqNames, 73 | totalPrice: showCost() 74 | } 75 | */ 76 | 77 | const groupedByName = {}; 78 | 79 | products.forEach(p => { 80 | if(groupedByName.hasOwnProperty(p.name)) { 81 | groupedByName[p.name].quantity += 1; 82 | groupedByName[p.name].totalPrice += p.price; 83 | } 84 | else { 85 | groupedByName[p.name] = { 86 | name: p.name, 87 | quantity: 1, 88 | totalPrice: p.price 89 | }; 90 | } 91 | }); 92 | 93 | const groups = Object.keys(groupedByName) 94 | .sort() 95 | .map(n => { 96 | return { 97 | name: n, 98 | quantity: groupedByName[n].quantity, 99 | totalPrice: groupedByName[n].totalPrice 100 | }; 101 | }); 102 | 103 | return { 104 | //products: Object.values(groupedByName).sort(x => x.name), 105 | products: groups, 106 | totalPrice: showCost() 107 | } 108 | } 109 | 110 | return { 111 | products: products, 112 | add: add, 113 | remove: remove, 114 | showCost: showCost, 115 | showProductTypes: showProductTypes, 116 | getInfo: getInfo 117 | }; 118 | } 119 | 120 | return { 121 | getProduct: getProduct, 122 | getShoppingCart: getShoppingCart 123 | }; 124 | } 125 | 126 | module.exports = solve(); 127 | -------------------------------------------------------------------------------- /Workshops/README.md: -------------------------------------------------------------------------------- 1 | # JavaScript OOP: Workshops 2 | --------------------------------------------------------------------------------