├── 0x00-ES6_basic
├── .eslintrc.js
├── .gitignore
├── 0-constants.js
├── 0-main.js
├── 1-block-scoped.js
├── 1-main.js
├── 10-loops.js
├── 10-main.js
├── 100-createIteratorObject.js
├── 100-main.js
├── 101-iterateThroughObject.js
├── 101-main.js
├── 11-createEmployeesObject.js
├── 11-main.js
├── 12-createReportObject.js
├── 12-main.js
├── 2-arrow.js
├── 2-main.js
├── 3-default-parameter.js
├── 3-main.js
├── 4-main.js
├── 4-rest-parameter.js
├── 5-main.js
├── 5-spread-operator.js
├── 6-main.js
├── 6-string-interpolation.js
├── 7-getBudgetObject.js
├── 7-main.js
├── 8-getBudgetCurrentYear.js
├── 8-main.js
├── 9-getFullBudget.js
├── 9-main.js
├── README.md
├── babel.config.js
├── package-lock.json
└── package.json
├── 0x01-ES6_promise
├── .eslintrc.js
├── .gitignore
├── 0-main.js
├── 0-promise.js
├── 1-main.js
├── 1-promise.js
├── 100-await.js
├── 100-main.js
├── 2-main.js
├── 2-then.js
├── 3-all.js
├── 3-main.js
├── 4-main.js
├── 4-user-promise.js
├── 5-main.js
├── 5-photo-reject.js
├── 6-final-user.js
├── 6-main.js
├── 7-load_balancer.js
├── 7-main.js
├── 8-main.js
├── 8-try.js
├── 9-main.js
├── 9-try.js
├── README.md
├── babel.config.js
├── package-lock.json
├── package.json
└── utils.js
├── 0x02-ES6_classes
├── .eslintrc.js
├── .gitignore
├── 0-classroom.js
├── 0-main.js
├── 1-main.js
├── 1-make_classrooms.js
├── 10-car.js
├── 10-main.js
├── 100-evcar.js
├── 100-main.js
├── 2-hbtn_course.js
├── 2-main.js
├── 3-currency.js
├── 3-main.js
├── 4-main.js
├── 4-pricing.js
├── 5-building.js
├── 5-main.js
├── 6-main.js
├── 6-sky_high.js
├── 7-airport.js
├── 7-main.js
├── 8-hbtn_class.js
├── 8-main.js
├── 9-hoisting.js
├── 9-main.js
├── README.md
├── babel.config.js
├── package-lock.json
└── package.json
├── 0x03-ES6_data_manipulation
├── .eslintrc.js
├── .gitignore
├── 0-get_list_students.js
├── 0-main.js
├── 1-get_list_student_ids.js
├── 1-main.js
├── 10-main.js
├── 10-update_uniq_items.js
├── 100-main.js
├── 100-weak.js
├── 2-get_students_by_loc.js
├── 2-main.js
├── 3-get_ids_sum.js
├── 3-main.js
├── 4-main.js
├── 4-update_grade_by_city.js
├── 5-main.js
├── 5-typed_arrays.js
├── 6-main.js
├── 6-set.js
├── 7-has_array_values.js
├── 7-main.js
├── 8-clean_set.js
├── 8-main.js
├── 9-groceries_list.js
├── 9-main.js
├── README.md
├── babel.config.js
├── package-lock.json
└── package.json
├── 0x04-TypeScript
├── .gitignore
├── README.md
├── task_0
│ ├── .eslintrc.js
│ ├── .gitignore
│ ├── js
│ │ ├── .gitignore
│ │ └── main.ts
│ ├── package.json
│ ├── tsconfig.json
│ └── webpack.config.js
├── task_1
│ ├── .gitignore
│ ├── js
│ │ └── main.ts
│ ├── package-lock.json
│ ├── package.json
│ ├── tsconfig.json
│ └── webpack.config.js
├── task_2
│ └── js
│ │ └── main.ts
├── task_3
│ ├── .gitignore
│ ├── dist
│ │ ├── bundle.js
│ │ └── index.html
│ ├── js
│ │ ├── crud.d.ts
│ │ ├── crud.js
│ │ ├── interface.ts
│ │ └── main.ts
│ ├── package-lock.json
│ ├── package.json
│ ├── tsconfig.json
│ └── webpack.config.js
├── task_4
│ ├── .gitignore
│ ├── js
│ │ ├── main.ts
│ │ └── subjects
│ │ │ ├── Cpp.ts
│ │ │ ├── Java.ts
│ │ │ ├── React.ts
│ │ │ ├── Subject.ts
│ │ │ └── Teacher.ts
│ ├── package-lock.json
│ ├── package.json
│ └── tsconfig.json
└── task_5
│ └── js
│ └── main.ts
└── README.md
/0x00-ES6_basic/.eslintrc.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | env: {
3 | browser: false,
4 | es6: true,
5 | jest: true,
6 | },
7 | extends: [
8 | 'airbnb-base',
9 | 'plugin:jest/all',
10 | ],
11 | globals: {
12 | Atomics: 'readonly',
13 | SharedArrayBuffer: 'readonly',
14 | },
15 | parserOptions: {
16 | ecmaVersion: 2018,
17 | sourceType: 'module',
18 | },
19 | plugins: ['jest'],
20 | rules: {
21 | 'no-console': 'off',
22 | 'no-shadow': 'off',
23 | 'no-restricted-syntax': [
24 | 'error',
25 | 'LabeledStatement',
26 | 'WithStatement',
27 | ],
28 | },
29 | overrides:[
30 | {
31 | files: ['*.js'],
32 | excludedFiles: 'babel.config.js',
33 | }
34 | ]
35 | };
36 |
--------------------------------------------------------------------------------
/0x00-ES6_basic/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 | /.pnp
6 | .pnp.js
7 |
8 | # testing
9 | /coverage
10 |
11 | # production
12 | /build
13 |
14 | # misc
15 | .DS_Store
16 | .env.local
17 | .env.development.local
18 | .env.test.local
19 | .env.production.local
20 |
21 | npm-debug.log*
22 | yarn-debug.log*
23 | yarn-error.log*
24 | nodesource_setup.sh
25 | *.swp
26 |
27 |
--------------------------------------------------------------------------------
/0x00-ES6_basic/0-constants.js:
--------------------------------------------------------------------------------
1 | export function taskFirst() {
2 | const task = 'I prefer const when I can.';
3 | return task;
4 | }
5 |
6 | export function getLast() {
7 | return ' is okay';
8 | }
9 |
10 | export function taskNext() {
11 | let combination = 'But sometimes let';
12 | combination += getLast();
13 |
14 | return combination;
15 | }
16 |
--------------------------------------------------------------------------------
/0x00-ES6_basic/0-main.js:
--------------------------------------------------------------------------------
1 | import { taskFirst, taskNext } from './0-constants.js';
2 |
3 | console.log(`${taskFirst()} ${taskNext()}`);
4 |
5 |
--------------------------------------------------------------------------------
/0x00-ES6_basic/1-block-scoped.js:
--------------------------------------------------------------------------------
1 | export default function taskBlock(trueOrFalse) {
2 | const task = false;
3 | const task2 = true;
4 |
5 | if (trueOrFalse) {
6 | const task = true;
7 | const task2 = false;
8 | if (task && task2) {
9 | return [task, task2];
10 | }
11 | }
12 |
13 | return [task, task2];
14 | }
15 |
--------------------------------------------------------------------------------
/0x00-ES6_basic/1-main.js:
--------------------------------------------------------------------------------
1 | import taskBlock from './1-block-scoped';
2 |
3 | console.log(taskBlock(true));
4 | console.log(taskBlock(false));
5 |
--------------------------------------------------------------------------------
/0x00-ES6_basic/10-loops.js:
--------------------------------------------------------------------------------
1 | export default function appendToEachArrayValue(array, appendString) {
2 | const newArray = array;
3 | for (const value of array) {
4 | const idx = array.indexOf(value);
5 | newArray[idx] = appendString + value;
6 | }
7 |
8 | return newArray;
9 | }
10 |
--------------------------------------------------------------------------------
/0x00-ES6_basic/10-main.js:
--------------------------------------------------------------------------------
1 | import appendToEachArrayValue from './10-loops';
2 |
3 | console.log(appendToEachArrayValue(['append', 'fixed', 'displayed'], 'correctly-'));
4 |
--------------------------------------------------------------------------------
/0x00-ES6_basic/100-createIteratorObject.js:
--------------------------------------------------------------------------------
1 | export default function createIteratorObject(report) {
2 | let result = [];
3 | for (const value of Object.values(report.allEmployees)) {
4 | result = [...result, ...value];
5 | }
6 |
7 | return result;
8 | }
9 |
--------------------------------------------------------------------------------
/0x00-ES6_basic/100-main.js:
--------------------------------------------------------------------------------
1 | import createIteratorObject from './100-createIteratorObject';
2 |
3 | import createEmployeesObject from './11-createEmployeesObject';
4 | import createReportObject from './12-createReportObject';
5 |
6 | const employees = {
7 | ...createEmployeesObject('engineering', ['Bob', 'Jane']),
8 | ...createEmployeesObject('marketing', ['Sylvie']),
9 | };
10 |
11 | const report = createReportObject(employees);
12 |
13 | const reportWithIterator = createIteratorObject(report);
14 |
15 | for (const item of Object.keys(reportWithIterator)) {
16 | console.log(item);
17 | }
18 |
--------------------------------------------------------------------------------
/0x00-ES6_basic/101-iterateThroughObject.js:
--------------------------------------------------------------------------------
1 | export default function iterateThroughObject(reportWithIterator) {
2 | return reportWithIterator.join(' | ');
3 | }
4 |
--------------------------------------------------------------------------------
/0x00-ES6_basic/101-main.js:
--------------------------------------------------------------------------------
1 | import createEmployeesObject from './11-createEmployeesObject';
2 | import createReportObject from './12-createReportObject';
3 | import createIteratorObject from './100-createIteratorObject';
4 | import iterateThroughObject from './101-iterateThroughObject';
5 |
6 | const employees = {
7 | ...createEmployeesObject('engineering', ['Bob', 'Jane']),
8 | ...createEmployeesObject('marketing', ['Sylvie']),
9 | };
10 |
11 | const report = createReportObject(employees);
12 | const reportWithIterator = createIteratorObject(report);
13 |
14 | console.log(iterateThroughObject(reportWithIterator));
15 |
--------------------------------------------------------------------------------
/0x00-ES6_basic/11-createEmployeesObject.js:
--------------------------------------------------------------------------------
1 | export default function createEmployeesObject(departmentName, employees) {
2 | const employee = { [departmentName]: employees };
3 | return employee;
4 | }
5 |
--------------------------------------------------------------------------------
/0x00-ES6_basic/11-main.js:
--------------------------------------------------------------------------------
1 | import createEmployeeObject from './11-createEmployeesObject';
2 |
3 | console.log(createEmployeeObject("Software", [ "Bob", "Sylvie" ]));
4 |
--------------------------------------------------------------------------------
/0x00-ES6_basic/12-createReportObject.js:
--------------------------------------------------------------------------------
1 | export default function createReportObject(employeesList) {
2 | return {
3 | allEmployees: {
4 | ...employeesList,
5 | },
6 | getNumberOfDepartments(employeesList) {
7 | return Object.keys(employeesList).length;
8 | },
9 | };
10 | }
11 |
--------------------------------------------------------------------------------
/0x00-ES6_basic/12-main.js:
--------------------------------------------------------------------------------
1 | import createEmployeesObject from './11-createEmployeesObject';
2 | import createReportObject from './12-createReportObject';
3 |
4 | const employees = {
5 | ...createEmployeesObject('engineering', ['Bob', 'Jane']),
6 | ...createReportObject('marketing', ['Sylvie']),
7 | };
8 |
9 | const report = createReportObject(employees);
10 | console.log(report.allEmployees);
11 |
12 | console.log(report.getNumberOfDepartments(report.allEmployees));
13 |
--------------------------------------------------------------------------------
/0x00-ES6_basic/2-arrow.js:
--------------------------------------------------------------------------------
1 | export default function getNeighborhoodsList() {
2 | this.sanFranciscoNeighborhoods = ['SOMA', 'Union Square'];
3 |
4 | const self = this;
5 | this.addNeighborhood = (newNeighborhood) => {
6 | self.sanFranciscoNeighborhoods.push(newNeighborhood);
7 | return self.sanFranciscoNeighborhoods;
8 | };
9 | }
10 |
--------------------------------------------------------------------------------
/0x00-ES6_basic/2-main.js:
--------------------------------------------------------------------------------
1 | import getNeighborhoodsList from './2-arrow.js';
2 |
3 | const neighborhoodsList = new getNeighborhoodsList();
4 | const res = neighborhoodsList.addNeighborhood('Noe Valley');
5 | console.log(res);
6 |
--------------------------------------------------------------------------------
/0x00-ES6_basic/3-default-parameter.js:
--------------------------------------------------------------------------------
1 | export default function getSumOfHoods(initialNumber, expansion1989 = 89, expansion2019 = 19) {
2 | return initialNumber + expansion1989 + expansion2019;
3 | }
4 |
--------------------------------------------------------------------------------
/0x00-ES6_basic/3-main.js:
--------------------------------------------------------------------------------
1 | import getSumOfHoods from './3-default-parameter.js';
2 |
3 | console.log(getSumOfHoods(34));
4 | console.log(getSumOfHoods(34, 3));
5 | console.log(getSumOfHoods(34, 3, 4));
6 |
7 |
--------------------------------------------------------------------------------
/0x00-ES6_basic/4-main.js:
--------------------------------------------------------------------------------
1 | import returnHowManyArguments from './4-rest-parameter.js';
2 |
3 | console.log(returnHowManyArguments("one"));
4 | console.log(returnHowManyArguments("one", "two", 3, "4th"));
5 |
6 |
--------------------------------------------------------------------------------
/0x00-ES6_basic/4-rest-parameter.js:
--------------------------------------------------------------------------------
1 | export default function returnHowManyArguments(...args) {
2 | return args.length;
3 | }
4 |
--------------------------------------------------------------------------------
/0x00-ES6_basic/5-main.js:
--------------------------------------------------------------------------------
1 | import concatArrays from "./5-spread-operator";
2 |
3 | console.log(concatArrays(['a', 'b'], ['c', 'd'], 'Hello'));
4 |
--------------------------------------------------------------------------------
/0x00-ES6_basic/5-spread-operator.js:
--------------------------------------------------------------------------------
1 | export default function concatArrays(array1, array2, string) {
2 | return [...array1, ...array2, ...string];
3 | }
4 |
--------------------------------------------------------------------------------
/0x00-ES6_basic/6-main.js:
--------------------------------------------------------------------------------
1 | import getSanFranciscoDescription from "./6-string-interpolation";
2 |
3 | console.log(getSanFranciscoDescription());
4 |
--------------------------------------------------------------------------------
/0x00-ES6_basic/6-string-interpolation.js:
--------------------------------------------------------------------------------
1 | export default function getSanFranciscoDescription() {
2 | const year = 2017;
3 | const budget = {
4 | income: '$119,868',
5 | gdp: '$154.2 billion',
6 | capita: '$178,479',
7 | };
8 |
9 | return `As of ${year}, it was the seventh-highest income county in the United States, with a per capita personal income of ${budget.income}. As of 2015, San Francisco proper had a GDP of ${budget.gdp}, and a GDP per capita of ${budget.capita}.`;
10 | }
11 |
--------------------------------------------------------------------------------
/0x00-ES6_basic/7-getBudgetObject.js:
--------------------------------------------------------------------------------
1 | export default function getBudgetObject(income, gdp, capita) {
2 | const budget = {
3 | income,
4 | gdp,
5 | capita,
6 | };
7 |
8 | return budget;
9 | }
10 |
--------------------------------------------------------------------------------
/0x00-ES6_basic/7-main.js:
--------------------------------------------------------------------------------
1 | import getBudgetObject from './7-getBudgetObject.js';
2 |
3 | console.log(getBudgetObject(400, 700, 900));
4 |
--------------------------------------------------------------------------------
/0x00-ES6_basic/8-getBudgetCurrentYear.js:
--------------------------------------------------------------------------------
1 | function getCurrentYear() {
2 | const date = new Date();
3 | return date.getFullYear();
4 | }
5 |
6 | export default function getBudgetForCurrentYear(income, gdp, capita) {
7 | const budget = {
8 | [`income-${getCurrentYear()}`]: income,
9 | [`gdp-${getCurrentYear()}`]: gdp,
10 | [`capita-${getCurrentYear()}`]: capita,
11 | };
12 |
13 | return budget;
14 | }
15 |
--------------------------------------------------------------------------------
/0x00-ES6_basic/8-main.js:
--------------------------------------------------------------------------------
1 | import getBudgetForCurrentYear from "./8-getBudgetCurrentYear";
2 |
3 | console.log(getBudgetForCurrentYear(2100, 5200, 1000));
4 |
--------------------------------------------------------------------------------
/0x00-ES6_basic/9-getFullBudget.js:
--------------------------------------------------------------------------------
1 | import getBudgetObject from './7-getBudgetObject';
2 |
3 | export default function getFullBudgetObject(income, gdp, capita) {
4 | const budget = getBudgetObject(income, gdp, capita);
5 | const fullBudget = {
6 | ...budget,
7 | getIncomeInDollars: (income) => `$${income}`,
8 | getIncomeInEuros: (income) => `${income} euros`,
9 | };
10 |
11 | return fullBudget;
12 | }
13 |
--------------------------------------------------------------------------------
/0x00-ES6_basic/9-main.js:
--------------------------------------------------------------------------------
1 | import getFullBudgetObject from './9-getFullBudget.js';
2 |
3 | const fullBudget = getFullBudgetObject(20, 50, 10);
4 |
5 | console.log(fullBudget.getIncomeInDollars(fullBudget.income));
6 | console.log(fullBudget.getIncomeInEuros(fullBudget.income));
7 |
--------------------------------------------------------------------------------
/0x00-ES6_basic/README.md:
--------------------------------------------------------------------------------
1 | # alx-frontend-javascript | 0x00. ES6 Basics
2 |
3 | ## Description:bulb:
4 |
5 | Javascript ES6
6 |
7 | - What ES6 is
8 | - New features introduced in ES6
9 | - The difference between a constant and a variable
10 | - Block-scoped variables
11 | - Arrow functions and function parameters default to them
12 | - Rest and spread function parameters
13 | - String templating in ES6
14 | - Object creation and their properties in ES6
15 | - Iterators and for-of loops
16 |
17 | ## Technologies & Tools:computer:
18 |
19 | [](https://jestjs.io/)
20 | [](https://git-scm.com/)
21 | [](https://ubuntu.com/)
22 | [](https://babeljs.io/)
23 | [](https://developer.mozilla.org/en-US/docs/Web/javascript)
24 | [](https://www.gnu.org/software/bash/)
25 | [](https://nodejs.org/en/)
26 | [](https://www.vim.org/)
27 | [](https://www.vagrantup.com/)
28 | [](https://code.visualstudio.com/)
29 | [](https://eslint.org/)
30 | [](https://github.com/)
31 |
32 | ---
33 |
34 | ## Resources:books:
35 |
36 | Read or watch:
37 |
38 | - [ECMAScript 6 - ECMAScript 2015](https://www.w3schools.com/js/js_es6.asp)
39 | - [Statements and declarations](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements)
40 | - [Arrow functions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions)
41 | - [Default parameters](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Default_parameters)
42 | - [Rest parameter](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters)
43 | - [Javascript ES6 — Iterables and Iterators](https://towardsdatascience.com/javascript-es6-iterables-and-iterators-de18b54f4d4)
44 |
45 | ---
46 |
47 | ## Requirements:hammer:
48 |
49 | - Ubuntu 18.04 LTS using NodeJS 12.22.x
50 | - Jest Testing Framework
51 | - ESLint
52 |
53 | ### Install NodeJS 12.22.x
54 |
55 | ```console
56 | foo@pop-os:~$ curl -sL https://deb.nodesource.com/setup_12.x -o nodesource_setup.sh
57 | foo@pop-os:~$ sudo bash nodesource_setup.sh
58 | foo@pop-os:~$ sudo apt install nodejs -y
59 | ```
60 |
61 | ### Check version
62 |
63 | ```console
64 | foo@pop-os:~$ nodejs -v
65 | v12.22.1
66 | foo@pop-os:~$ npm -v
67 | 6.14.12
68 | ```
69 |
70 | ### Install Jest, Babel, and ESLint
71 |
72 | ```console
73 | foo@pop-os:~$ npm install --save-dev jest
74 | foo@pop-os:~$ npm install --save-dev babel-jest @babel/core @babel/preset-env
75 | foo@pop-os:~$ npm install --save-dev eslint
76 | ```
77 |
78 |
79 | .eslintrc.js
80 | ```javascript
81 | module.exports = {
82 | env: {
83 | browser: false,
84 | es6: true,
85 | jest: true,
86 | },
87 | extends: [
88 | 'airbnb-base',
89 | 'plugin:jest/all',
90 | ],
91 | globals: {
92 | Atomics: 'readonly',
93 | SharedArrayBuffer: 'readonly',
94 | },
95 | parserOptions: {
96 | ecmaVersion: 2018,
97 | sourceType: 'module',
98 | },
99 | plugins: ['jest'],
100 | rules: {
101 | 'no-console': 'off',
102 | 'no-shadow': 'off',
103 | 'no-restricted-syntax': [
104 | 'error',
105 | 'LabeledStatement',
106 | 'WithStatement',
107 | ],
108 | },
109 | overrides:[
110 | {
111 | files: ['*.js'],
112 | excludedFiles: 'babel.config.js',
113 | }
114 | ]
115 | };
116 | ```
117 |
118 |
119 | ---
120 |
121 | ## Files:card_file_box:
122 |
123 | ### [0. Const or let?](./0-constants.js)
124 |
125 | ### [1. Block Scope](./1-block-scoped.js)
126 |
127 | ### [2. Arrow functions](./2-arrow.js)
128 |
129 | ### [3. Parameter defaults](./3-default-parameter.js)
130 |
131 | ### [4. Rest parameter syntax for functions](./4-rest-parameter.js)
132 |
133 | ### [5. The wonders of spread syntax](./5-spread-operator.js)
134 |
135 | ### [6. Take advantage of template literals](./6-string-interpolation.js)
136 |
137 | ### [7. Object property value shorthand syntax](./7-getBudgetObject.js)
138 |
139 | ### [8. No need to create empty objects before adding in properties](./8-getBudgetCurrentYear.js)
140 |
141 | ### [9. ES6 method properties](./9-getFullBudget.js)
142 |
143 | ### [10. For...of Loops](./10-loops.js)
144 |
145 | ### [11. Iterator](./11-createEmployeesObject.js)
146 |
147 | ### [12. Let's create a report object](./12-createReportObject.js)
148 |
149 | ## Author
150 |
151 | - **Joseph Mahiuha** (@Mahiuha) - [
](https://mahiuha.github.io/josephmahiuha/)
152 | [
](https://twitter.com/Joseph_Mahiuha)
153 | [
](https://www.linkedin.com/in/joseph-mahiuha-498a52162/)
154 | [
](https://github.com/Mahiuha)
155 |
--------------------------------------------------------------------------------
/0x00-ES6_basic/babel.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | presets: [
3 | [
4 | '@babel/preset-env',
5 | {
6 | targets: {
7 | node: 'current',
8 | },
9 | },
10 | ],
11 | ],
12 | };
13 |
--------------------------------------------------------------------------------
/0x00-ES6_basic/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "scripts": {
3 | "lint": "./node_modules/.bin/eslint",
4 | "check-lint": "lint [0-9]*.js",
5 | "dev": "npx babel-node",
6 | "test": "jest",
7 | "full-test": "./node_modules/.bin/eslint [0-9]*.js && jest"
8 | },
9 | "devDependencies": {
10 | "@babel/core": "^7.6.0",
11 | "@babel/node": "^7.8.0",
12 | "@babel/preset-env": "^7.6.0",
13 | "eslint": "^6.4.0",
14 | "eslint-config-airbnb-base": "^14.0.0",
15 | "eslint-plugin-import": "^2.18.2",
16 | "eslint-plugin-jest": "^22.17.0",
17 | "jest": "^29.3.1"
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/0x01-ES6_promise/.eslintrc.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | env: {
3 | browser: false,
4 | es6: true,
5 | jest: true,
6 | },
7 | extends: [
8 | 'airbnb-base',
9 | 'plugin:jest/all',
10 | ],
11 | globals: {
12 | Atomics: 'readonly',
13 | SharedArrayBuffer: 'readonly',
14 | },
15 | parserOptions: {
16 | ecmaVersion: 2018,
17 | sourceType: 'module',
18 | },
19 | plugins: ['jest'],
20 | rules: {
21 | 'no-console': 'off',
22 | 'no-shadow': 'off',
23 | 'no-restricted-syntax': [
24 | 'error',
25 | 'LabeledStatement',
26 | 'WithStatement',
27 | ],
28 | },
29 | overrides:[
30 | {
31 | files: ['*.js'],
32 | excludedFiles: 'babel.config.js',
33 | }
34 | ]
35 | };
36 |
--------------------------------------------------------------------------------
/0x01-ES6_promise/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 | /.pnp
6 | .pnp.js
7 |
8 | # testing
9 | /coverage
10 |
11 | # production
12 | /build
13 |
14 | # misc
15 | .DS_Store
16 | .env.local
17 | .env.development.local
18 | .env.test.local
19 | .env.production.local
20 |
21 | npm-debug.log*
22 | yarn-debug.log*
23 | yarn-error.log*
24 | nodesource_setup.sh
25 | *.swp
26 |
--------------------------------------------------------------------------------
/0x01-ES6_promise/0-main.js:
--------------------------------------------------------------------------------
1 | import getResponseFromAPI from './0-promise';
2 |
3 | const response = getResponseFromAPI();
4 | console.log(response instanceof Promise);
5 |
--------------------------------------------------------------------------------
/0x01-ES6_promise/0-promise.js:
--------------------------------------------------------------------------------
1 | function getFullResponseFromAPI(success) {
2 | return new Promise((resolve, reject) => {
3 | if (success) resolve({ status: 200, body: 'Success' });
4 | reject(Error('The fake API is not working currently'));
5 | });
6 | }
7 |
8 | export default getFullResponseFromAPI;
9 |
--------------------------------------------------------------------------------
/0x01-ES6_promise/1-main.js:
--------------------------------------------------------------------------------
1 | import getFullResponseFromAPI from './1-promise';
2 |
3 | console.log(getFullResponseFromAPI(true));
4 | console.log(getFullResponseFromAPI(false));
5 |
--------------------------------------------------------------------------------
/0x01-ES6_promise/1-promise.js:
--------------------------------------------------------------------------------
1 | function getFullResponseFromAPI(success) {
2 | return new Promise((resolve, reject) => {
3 | if (success) resolve({ status: 200, body: 'Success' });
4 | reject(Error('The fake API is not working currently'));
5 | });
6 | }
7 |
8 | export default getFullResponseFromAPI;
9 |
--------------------------------------------------------------------------------
/0x01-ES6_promise/100-await.js:
--------------------------------------------------------------------------------
1 | import { uploadPhoto, createUser } from './utils';
2 |
3 | export default async function asyncUploadUser() {
4 | let photo;
5 | let user;
6 | try {
7 | photo = await uploadPhoto();
8 | user = await createUser();
9 | } catch (error) {
10 | photo = null;
11 | user = null;
12 | }
13 | return { photo, user };
14 | }
15 |
--------------------------------------------------------------------------------
/0x01-ES6_promise/100-main.js:
--------------------------------------------------------------------------------
1 | import asyncUploader from "./100-await";
2 |
3 | const test = async () => {
4 | const value = await asyncUploadUser();
5 | console.log(value);
6 | };
7 |
8 | test();
9 |
--------------------------------------------------------------------------------
/0x01-ES6_promise/2-main.js:
--------------------------------------------------------------------------------
1 | import handleResponseFromAPI from "./2-then";
2 |
3 | const promise = Promise.resolve();
4 | handleResponseFromAPI(promise);
5 |
--------------------------------------------------------------------------------
/0x01-ES6_promise/2-then.js:
--------------------------------------------------------------------------------
1 | function handleResponseFromAPI(promise) {
2 | const body = { status: 200, body: 'success' };
3 |
4 | return promise
5 | .then(() => body)
6 | .catch((error) => error)
7 | .finally(() => console.log('Got a response from the API'));
8 | }
9 | export default handleResponseFromAPI;
10 |
--------------------------------------------------------------------------------
/0x01-ES6_promise/3-all.js:
--------------------------------------------------------------------------------
1 | import { createUser, uploadPhoto } from './utils';
2 |
3 | function handleProfileSignup() {
4 | return Promise.all([uploadPhoto(), createUser()])
5 | .then((data) => {
6 | console.log(`${data[0].body} ${data[1].firstName} ${data[1].lastName}`);
7 | })
8 | .catch(() => console.log('Signup system offline'));
9 | }
10 |
11 | export default handleProfileSignup;
12 |
--------------------------------------------------------------------------------
/0x01-ES6_promise/3-main.js:
--------------------------------------------------------------------------------
1 | import handleProfileSignup from "./3-all";
2 |
3 | handleProfileSignup();
4 |
--------------------------------------------------------------------------------
/0x01-ES6_promise/4-main.js:
--------------------------------------------------------------------------------
1 | import signUpUser from "./4-user-promise";
2 |
3 | console.log(signUpUser("Bob", "Dylan"));
4 |
--------------------------------------------------------------------------------
/0x01-ES6_promise/4-user-promise.js:
--------------------------------------------------------------------------------
1 | function signUpUser(firstName, lastName) {
2 | return Promise.resolve({
3 | firstName,
4 | lastName,
5 | });
6 | }
7 |
8 | export default signUpUser;
9 |
--------------------------------------------------------------------------------
/0x01-ES6_promise/5-main.js:
--------------------------------------------------------------------------------
1 | import uploadPhoto from './5-photo-reject';
2 |
3 | console.log(uploadPhoto('guillaume.jpg'));
4 |
--------------------------------------------------------------------------------
/0x01-ES6_promise/5-photo-reject.js:
--------------------------------------------------------------------------------
1 | export default function uploadPhoto(filename) {
2 | return Promise.reject(new Error(`${filename} cannot be processed`));
3 | }
4 |
--------------------------------------------------------------------------------
/0x01-ES6_promise/6-final-user.js:
--------------------------------------------------------------------------------
1 | import signUpUser from './4-user-promise';
2 | import uploadPhoto from './5-photo-reject';
3 |
4 | export default function handleProfileSignup(firstName, lastName, fileName) {
5 | const promises = [signUpUser(firstName, lastName), uploadPhoto(fileName)];
6 | const result = [];
7 | return Promise.allSettled(promises).then((results) => {
8 | results.map(({ status, value, reason }) => (
9 | result.push({
10 | status,
11 | value: status === 'rejected' ? reason.toString() : value,
12 | })
13 | ));
14 | return result;
15 | });
16 | }
17 |
--------------------------------------------------------------------------------
/0x01-ES6_promise/6-main.js:
--------------------------------------------------------------------------------
1 | import handleProfileSignup from './6-final-user';
2 |
3 | console.log(handleProfileSignup("Bob", "Dylan", "bob_dylan.jpg"));
4 |
--------------------------------------------------------------------------------
/0x01-ES6_promise/7-load_balancer.js:
--------------------------------------------------------------------------------
1 | export default function loadBalancer(chinaDownload, USDownload) {
2 | return Promise.race([chinaDownload, USDownload]);
3 | }
4 |
--------------------------------------------------------------------------------
/0x01-ES6_promise/7-main.js:
--------------------------------------------------------------------------------
1 | import loadBalancer from "./7-load_balancer";
2 |
3 | const ukSuccess = 'Downloading from UK is faster';
4 | const frSuccess = 'Downloading from FR is faster';
5 |
6 | const promiseUK = new Promise(function(resolve, reject) {
7 | setTimeout(resolve, 100, ukSuccess);
8 | });
9 |
10 | const promiseUKSlow = new Promise(function(resolve, reject) {
11 | setTimeout(resolve, 400, ukSuccess);
12 | });
13 |
14 | const promiseFR = new Promise(function(resolve, reject) {
15 | setTimeout(resolve, 200, frSuccess);
16 | });
17 |
18 | const test = async () => {
19 | console.log(await loadBalancer(promiseUK, promiseFR));
20 | console.log(await loadBalancer(promiseUKSlow, promiseFR));
21 | }
22 |
23 | test();
24 |
--------------------------------------------------------------------------------
/0x01-ES6_promise/8-main.js:
--------------------------------------------------------------------------------
1 | import divideFunction from './8-try';
2 |
3 | console.log(divideFunction(10, 2));
4 | console.log(divideFunction(10, 0));
5 |
--------------------------------------------------------------------------------
/0x01-ES6_promise/8-try.js:
--------------------------------------------------------------------------------
1 | export default function divideFunction(numerator, denominator) {
2 | try {
3 | if (denominator === 0) {
4 | throw new Error();
5 | }
6 | return numerator / denominator;
7 | } catch (error) {
8 | throw Error('cannot divide by 0');
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/0x01-ES6_promise/9-main.js:
--------------------------------------------------------------------------------
1 | import guardrail from './9-try';
2 | import divideFunction from './8-try';
3 |
4 | console.log(guardrail(() => { return divideFunction(10, 2)}));
5 | console.log(guardrail(() => { return divideFunction(10, 0)}));
6 |
--------------------------------------------------------------------------------
/0x01-ES6_promise/9-try.js:
--------------------------------------------------------------------------------
1 | export default function guardrail(mathFunction) {
2 | const queue = [];
3 | let res;
4 | try {
5 | res = mathFunction();
6 | } catch (error) {
7 | res = `Error: ${error.message}`;
8 | }
9 | queue.push(res);
10 | queue.push('Guardrail was processed');
11 |
12 | return queue;
13 | }
14 |
--------------------------------------------------------------------------------
/0x01-ES6_promise/README.md:
--------------------------------------------------------------------------------
1 | # 0x01. ES6 Promises
2 |
3 | ## Description:bulb:
4 |
5 | One simply does not use async/await without knowing promises!
6 |
7 | - Promises (how, why, and what)
8 | - How to use the `then`, `resolve`, `catch` methods
9 | - How to use every method of the Promise object
10 | - Throw / Try
11 | - The await operator
12 | - How to use an `async` function
13 |
14 | ## Technologies & Tools:computer:
15 |
16 | [](https://jestjs.io/)
17 | [](https://git-scm.com/)
18 | [](https://ubuntu.com/)
19 | [](https://babeljs.io/)
20 | [](https://developer.mozilla.org/en-US/docs/Web/javascript)
21 | [](https://www.gnu.org/software/bash/)
22 | [](https://nodejs.org/en/)
23 | [](https://www.vim.org/)
24 | [](https://www.vagrantup.com/)
25 | [](https://code.visualstudio.com/)
26 | [](https://eslint.org/)
27 | [](https://github.com/)
28 |
29 | ---
30 |
31 | ## Resources:books:
32 |
33 | Read or watch:
34 |
35 | - [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
36 | - [JavaScript Promise: An introduction](https://web.dev/promises/)
37 | - [Await](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await)
38 | - [Async](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function)
39 | - [Throw / Try](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/throw)
40 |
41 | ---
42 |
43 | ## Requirements:hammer:
44 |
45 | - Ubuntu 18.04 LTS using NodeJS 12.22.x
46 | - Jest Testing Framework
47 | - ESLint
48 |
49 | ### Install NodeJS 12.22.x
50 |
51 | ```console
52 | foo@pop-os:~$ curl -sL https://deb.nodesource.com/setup_12.x -o nodesource_setup.sh
53 | foo@pop-os:~$ sudo bash nodesource_setup.sh
54 | foo@pop-os:~$ sudo apt install nodejs -y
55 | ```
56 |
57 | ### Check version
58 |
59 | ```console
60 | foo@pop-os:~$ nodejs -v
61 | v12.22.1
62 | foo@pop-os:~$ npm -v
63 | 6.14.12
64 | ```
65 |
66 | ### Install Jest, Babel, and ESLint
67 |
68 | ```console
69 | foo@pop-os:~$ npm install --save-dev jest
70 | foo@pop-os:~$ npm install --save-dev babel-jest @babel/core @babel/preset-env
71 | foo@pop-os:~$ npm install --save-dev eslint
72 | ```
73 |
74 | ---
75 |
76 | ## Files:card_file_box:
77 |
78 | ### [0. Keep every promise you make and only make promises you can keep](./0-promise.js)
79 |
80 | ### [1. Don't make a promise...if you know you can't keep it](./1-promise.js)
81 |
82 | ### [2. Catch me if you can!](./2-then.js)
83 |
84 | ### [3. Handle multiple successful promises](./3-all.js)
85 |
86 | ### [4. Simple promise](./4-user-promise.js)
87 |
88 | ### [5. Reject the promises](./5-photo-reject.js)
89 |
90 | ### [6. Handle multiple promises](./6-final-user.js)
91 |
92 | ### [7. Load balancer](./7-load_balancer.js)
93 |
94 | ### [8. Throw error / try catch](./8-try.js)
95 |
96 | ### [9. Throw an error](./9-try.js)
97 |
98 | ### [10. Await / Async](./100-await.js)
99 |
100 | ---
101 |
102 | ## Author
103 |
104 | - **Joseph Mahiuha** (@Mahiuha) - [
](https://mahiuha.github.io/josephmahiuha/)
105 | [
](https://twitter.com/Joseph_Mahiuha)
106 | [
](https://www.linkedin.com/in/joseph-mahiuha-498a52162/)
107 | [
](https://github.com/Mahiuha)
108 |
--------------------------------------------------------------------------------
/0x01-ES6_promise/babel.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | presets: [
3 | [
4 | '@babel/preset-env',
5 | {
6 | targets: {
7 | node: 'current',
8 | },
9 | },
10 | ],
11 | ],
12 | };
13 |
--------------------------------------------------------------------------------
/0x01-ES6_promise/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "scripts": {
3 | "lint": "./node_modules/.bin/eslint",
4 | "check-lint": "lint [0-9]*.js",
5 | "dev": "npx babel-node",
6 | "test": "jest",
7 | "full-test": "./node_modules/.bin/eslint [0-9]*.js && jest"
8 | },
9 | "devDependencies": {
10 | "@babel/cli": "^7.20.7",
11 | "@babel/core": "^7.20.12",
12 | "@babel/node": "^7.8.0",
13 | "@babel/preset-env": "^7.20.2",
14 | "babel-jest": "^29.3.1",
15 | "eslint": "^6.8.0",
16 | "eslint-config-airbnb-base": "^14.0.0",
17 | "eslint-plugin-import": "^2.18.2",
18 | "eslint-plugin-jest": "^22.17.0",
19 | "jest": "^29.3.1"
20 | },
21 | "dependencies": {
22 | "isomorphic-fetch": "^3.0.0"
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/0x01-ES6_promise/utils.js:
--------------------------------------------------------------------------------
1 | export function uploadPhoto() {
2 | return Promise.resolve({
3 | status: 200,
4 | body: 'photo-profile-1',
5 | });
6 | }
7 |
8 |
9 | export function createUser() {
10 | return Promise.resolve({
11 | firstName: 'Guillaume',
12 | lastName: 'Salva',
13 | });
14 | }
15 |
--------------------------------------------------------------------------------
/0x02-ES6_classes/.eslintrc.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | env: {
3 | browser: false,
4 | es6: true,
5 | jest: true,
6 | },
7 | extends: [
8 | 'airbnb-base',
9 | 'plugin:jest/all',
10 | ],
11 | globals: {
12 | Atomics: 'readonly',
13 | SharedArrayBuffer: 'readonly',
14 | },
15 | parserOptions: {
16 | ecmaVersion: 2018,
17 | sourceType: 'module',
18 | },
19 | plugins: ['jest'],
20 | rules: {
21 | 'max-classes-per-file': 'off',
22 | 'no-underscore-dangle': 'off',
23 | 'no-console': 'off',
24 | 'no-shadow': 'off',
25 | 'no-restricted-syntax': [
26 | 'error',
27 | 'LabeledStatement',
28 | 'WithStatement',
29 | ],
30 | },
31 | overrides:[
32 | {
33 | files: ['*.js'],
34 | excludedFiles: 'babel.config.js',
35 | }
36 | ]
37 | };
38 |
--------------------------------------------------------------------------------
/0x02-ES6_classes/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 | /.pnp
6 | .pnp.js
7 |
8 | # testing
9 | /coverage
10 |
11 | # production
12 | /build
13 |
14 | # misc
15 | .DS_Store
16 | .env.local
17 | .env.development.local
18 | .env.test.local
19 | .env.production.local
20 |
21 | npm-debug.log*
22 | yarn-debug.log*
23 | yarn-error.log*
24 | nodesource_setup.sh
25 | *.swp
26 |
27 |
--------------------------------------------------------------------------------
/0x02-ES6_classes/0-classroom.js:
--------------------------------------------------------------------------------
1 | export default class ClassRoom {
2 | constructor(maxStudentsSize) {
3 | this._maxStudentsSize = maxStudentsSize;
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/0x02-ES6_classes/0-main.js:
--------------------------------------------------------------------------------
1 | import ClassRoom from './0-classroom';
2 |
3 | const room = new ClassRoom(10);
4 | console.log(room._maxStudentsSize);
5 |
--------------------------------------------------------------------------------
/0x02-ES6_classes/1-main.js:
--------------------------------------------------------------------------------
1 | import initializeRooms from './1-make_classrooms';
2 |
3 | console.log(initializeRooms());
4 |
--------------------------------------------------------------------------------
/0x02-ES6_classes/1-make_classrooms.js:
--------------------------------------------------------------------------------
1 | import ClassRoom from './0-classroom';
2 |
3 | export default function initializeRooms() {
4 | const rooms = [new ClassRoom(19), new ClassRoom(20), new ClassRoom(34)];
5 | return rooms;
6 | }
7 |
--------------------------------------------------------------------------------
/0x02-ES6_classes/10-car.js:
--------------------------------------------------------------------------------
1 | export default class Car {
2 | constructor(brand, motor, color) {
3 | this._brand = brand;
4 | this._motor = motor;
5 | this._color = color;
6 | }
7 |
8 | static get [Symbol.species]() {
9 | return this;
10 | }
11 |
12 | cloneCar() {
13 | const Species = this.constructor[Symbol.species];
14 | return new Species();
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/0x02-ES6_classes/10-main.js:
--------------------------------------------------------------------------------
1 | import Car from './10-car';
2 |
3 | class TestCar extends Car {}
4 |
5 | const tc1 = new TestCar('Nissan', 'Turbo', 'Pink');
6 | const tc2 = tc1.cloneCar();
7 |
8 | console.log(tc1);
9 | console.log(tc1 instanceof TestCar);
10 |
11 | console.log(tc2);
12 | console.log(tc2 instanceof TestCar);
13 |
14 | console.log(tc1 === tc2);
15 |
--------------------------------------------------------------------------------
/0x02-ES6_classes/100-evcar.js:
--------------------------------------------------------------------------------
1 | import Car from './10-car';
2 |
3 | export default class EVCar extends Car {
4 | constructor(brand, motor, color, range) {
5 | super(brand, motor, color);
6 | this._range = range;
7 | }
8 |
9 | static get [Symbol.species]() {
10 | return Car;
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/0x02-ES6_classes/100-main.js:
--------------------------------------------------------------------------------
1 | import EVCar from './100-evcar';
2 |
3 | const ec1 = new EVCar("Tesla", "Turbo", "Red", "250");
4 | console.log(ec1);
5 |
6 | const ec2 = ec1.cloneCar();
7 | console.log(ec2);
8 |
9 |
--------------------------------------------------------------------------------
/0x02-ES6_classes/2-hbtn_course.js:
--------------------------------------------------------------------------------
1 | export default class HolbertonCourse {
2 | constructor(name, length, students) {
3 | if (typeof name !== 'string' || typeof length !== 'number' || !Array.isArray(students)) {
4 | throw new Error('Invalid input type');
5 | }
6 | this._name = name;
7 | this._length = length;
8 | this._students = students;
9 | }
10 |
11 | get name() {
12 | return this._name;
13 | }
14 |
15 | set name(value) {
16 | if (typeof value !== 'string') {
17 | throw new Error('Invalid input type');
18 | }
19 | this._name = value;
20 | }
21 |
22 | get length() {
23 | return this._length;
24 | }
25 |
26 | set length(value) {
27 | if (typeof value !== 'number') {
28 | throw new Error('Invalid input type');
29 | }
30 | this._length = value;
31 | }
32 |
33 | get students() {
34 | return this._students;
35 | }
36 |
37 | set students(value) {
38 | if (!Array.isArray(value)) {
39 | throw new Error('Invalid input type');
40 | }
41 | this._students = value;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/0x02-ES6_classes/2-main.js:
--------------------------------------------------------------------------------
1 | import HolbertonCourse from './2-hbtn_course';
2 |
3 | const c1 = new HolbertonCourse('ES6', 1, ['Bob', 'Jane']);
4 | console.log(c1.name);
5 | c1.name = 'Python 101';
6 | console.log(c1);
7 |
8 | try {
9 | c1.name = 12;
10 | } catch (err) {
11 | console.log(err);
12 | }
13 |
14 | try {
15 | const c2 = new HolbertonCourse('ES6', '1', ['Bob', 'Jane']);
16 | } catch (err) {
17 | console.log(err);
18 | }
19 |
--------------------------------------------------------------------------------
/0x02-ES6_classes/3-currency.js:
--------------------------------------------------------------------------------
1 | export default class Currency {
2 | constructor(code, name) {
3 | this._code = code;
4 | this._name = name;
5 | }
6 |
7 | get code() {
8 | return this._code;
9 | }
10 |
11 | get name() {
12 | return this._name;
13 | }
14 |
15 | set code(code) {
16 | this._code = code;
17 | }
18 |
19 | set name(name) {
20 | this._name = name;
21 | }
22 |
23 | displayFullCurrency() {
24 | return `${this._name} (${this._code})`;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/0x02-ES6_classes/3-main.js:
--------------------------------------------------------------------------------
1 | import Currency from "./3-currency";
2 |
3 | const dollar = new Currency('$', 'Dollars');
4 | console.log(dollar.displayFullCurrency());
5 |
6 |
--------------------------------------------------------------------------------
/0x02-ES6_classes/4-main.js:
--------------------------------------------------------------------------------
1 | import Pricing from './4-pricing';
2 | import Currency from './3-currency';
3 |
4 | const p = new Pricing(100, new Currency("EUR", "Euro"))
5 | console.log(p);
6 | console.log(p.displayFullPrice());
7 |
8 |
--------------------------------------------------------------------------------
/0x02-ES6_classes/4-pricing.js:
--------------------------------------------------------------------------------
1 | import Currency from './3-currency';
2 |
3 | export default class Pricing {
4 | constructor(amount, currency) {
5 | this._amount = amount;
6 | this._currency = currency;
7 | }
8 |
9 | get amount() {
10 | return this._amount;
11 | }
12 |
13 | get currency() {
14 | return this._currency;
15 | }
16 |
17 | set amount(amount) {
18 | this._amount = amount;
19 | }
20 |
21 | set currency(currency) {
22 | this._currency = currency;
23 | }
24 |
25 | displayFullPrice() {
26 | return `${this._amount} ${new Currency(this._currency.code, this._currency.name).displayFullCurrency()}`;
27 | }
28 |
29 | static convertPrice(amount, conversionRate) {
30 | return amount * conversionRate;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/0x02-ES6_classes/5-building.js:
--------------------------------------------------------------------------------
1 | export default class Building {
2 | constructor(sqft) {
3 | if (this.constructor !== Building && typeof this.evacuationWarningMesagge !== 'function') {
4 | throw new Error('Class extending Building must override evacuationWarningMessage');
5 | }
6 | this._sqft = sqft;
7 | }
8 |
9 | get sqft() {
10 | return this._sqft;
11 | }
12 |
13 | set sqft(sqft) {
14 | this._sqft = sqft;
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/0x02-ES6_classes/5-main.js:
--------------------------------------------------------------------------------
1 | import Building from './5-building';
2 |
3 | const b = new Building(100);
4 | console.log(b);
5 |
6 | class TestBuilding extends Building {}
7 |
8 | try {
9 | new TestBuilding(200)
10 | }
11 | catch(err) {
12 | console.log(err);
13 | }
14 |
15 |
--------------------------------------------------------------------------------
/0x02-ES6_classes/6-main.js:
--------------------------------------------------------------------------------
1 | import SkyHighBuilding from './6-sky_high';
2 |
3 | const building = new SkyHighBuilding(140, 60);
4 | console.log(building.sqft);
5 | console.log(building.floors);
6 | console.log(building.evacuationWarningMessage());
7 |
--------------------------------------------------------------------------------
/0x02-ES6_classes/6-sky_high.js:
--------------------------------------------------------------------------------
1 | import Building from './5-building';
2 |
3 | export default class SkyHighBuilding extends Building {
4 | constructor(sqft, floors) {
5 | super(sqft);
6 | this.floors = floors;
7 | }
8 |
9 | get floors() {
10 | return this._floors;
11 | }
12 |
13 | set floors(newFloors) {
14 | if (typeof newFloors !== 'number') {
15 | throw TypeError('Floors must be a number');
16 | }
17 | this._floors = newFloors;
18 | }
19 |
20 | evacuationWarningMessage() {
21 | return `Evacuate slowly the ${this._floors} floors`;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/0x02-ES6_classes/7-airport.js:
--------------------------------------------------------------------------------
1 | export default class Airport {
2 | constructor(name, code) {
3 | this._name = name;
4 | this._code = code;
5 | }
6 |
7 | get [Symbol.toStringTag]() {
8 | return `${this._code}`;
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/0x02-ES6_classes/7-main.js:
--------------------------------------------------------------------------------
1 | import Airport from './7-airport';
2 |
3 | const airportSF = new Airport('San Francisco Airport', 'SFO');
4 | console.log(airportSF);
5 | console.log(airportSF.toString());
6 |
--------------------------------------------------------------------------------
/0x02-ES6_classes/8-hbtn_class.js:
--------------------------------------------------------------------------------
1 | export default class HolbertonClass {
2 | constructor(size, location) {
3 | this._size = size;
4 | this._location = location;
5 | }
6 |
7 | [Symbol.toPrimitive](hint) {
8 | if (hint === 'number') {
9 | return this._size;
10 | }
11 | return this._location;
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/0x02-ES6_classes/8-main.js:
--------------------------------------------------------------------------------
1 | import HolbertonClass from './8-hbtn_class';
2 |
3 | const hc = new HolbertonClass(12, 'Mezzanine');
4 | console.log(Number(hc));
5 | console.log(String(hc));
6 |
--------------------------------------------------------------------------------
/0x02-ES6_classes/9-hoisting.js:
--------------------------------------------------------------------------------
1 | export class HolbertonClass {
2 | constructor(year, location) {
3 | this._year = year;
4 | this._location = location;
5 | }
6 |
7 | get year() {
8 | return this._year;
9 | }
10 |
11 | get location() {
12 | return this._location;
13 | }
14 | }
15 |
16 | export class StudentHolberton {
17 | constructor(firstName, lastName, holbertonClass) {
18 | this._firstName = firstName;
19 | this._lastName = lastName;
20 | this._holbertonClass = holbertonClass;
21 | }
22 |
23 | get fullName() {
24 | return `${this._firstName} ${this._lastName}`;
25 | }
26 |
27 | get holbertonClass() {
28 | return this._holbertonClass;
29 | }
30 |
31 | get fullStudentDescription() {
32 | return `${this._firstName} ${this._lastName} - ${this._holbertonClass.year} - ${this._holbertonClass.location}`;
33 | }
34 | }
35 |
36 | const class2020 = new HolbertonClass(2020, 'San Francisco');
37 | const student1 = new StudentHolberton('Guillaume', 'Salva', class2020);
38 | const student2 = new StudentHolberton('John', 'Doe', class2020);
39 | const student3 = new StudentHolberton('Albert', 'Clinton', new HolbertonClass(2019, 'San Francisco'));
40 | const student4 = new StudentHolberton('Donald', 'Bush', new HolbertonClass(2019, 'San Francisco'));
41 | const student5 = new StudentHolberton('Jason', 'Sandler', new HolbertonClass(2019, 'San Francisco'));
42 |
43 | const listOfStudents = [student1, student2, student3, student4, student5];
44 | console.log(listOfStudents);
45 | console.log(listOfStudents.map(student => student.fullStudentDescription));
46 | export {listOfStudents};
47 |
48 |
--------------------------------------------------------------------------------
/0x02-ES6_classes/9-main.js:
--------------------------------------------------------------------------------
1 | import listOfStudents from './9-hoisting';
2 |
3 | console.log(listOfStudents);
4 |
5 | const listPrinted = listOfStudents.map(
6 | (student) => student.fullStudentDescription,
7 | );
8 |
9 | console.log(listPrinted);
10 |
--------------------------------------------------------------------------------
/0x02-ES6_classes/README.md:
--------------------------------------------------------------------------------
1 | # 0x10. ES6 classes
2 |
3 | ## Description:bulb:
4 |
5 | ES6 Classes for all the things!
6 |
7 | - How to define a Class
8 | - How to add methods to a class
9 | - Why and how to add a static method to a class
10 | - How to extend a class from another
11 | - Metaprogramming and symbols
12 |
13 | ## Technologies & Tools:computer:
14 |
15 | [](https://jestjs.io/)
16 | [](https://git-scm.com/)
17 | [](https://ubuntu.com/)
18 | [](https://babeljs.io/)
19 | [](https://developer.mozilla.org/en-US/docs/Web/javascript)
20 | [](https://www.gnu.org/software/bash/)
21 | [](https://nodejs.org/en/)
22 | [](https://www.vim.org/)
23 | [](https://www.vagrantup.com/)
24 | [](https://code.visualstudio.com/)
25 | [](https://eslint.org/)
26 | [](https://github.com/)
27 |
28 | ---
29 |
30 | ## Resources:books:
31 |
32 | Read or watch:
33 |
34 | - [Classes](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes)
35 | - [Metaprogramming](https://www.keithcirkel.co.uk/metaprogramming-in-es6-symbols/#symbolspecies)
36 |
37 | ---
38 |
39 | ## Requirements:hammer:
40 |
41 | - Ubuntu 18.04 LTS using NodeJS 12.22.x
42 | - Jest Testing Framework
43 | - ESLint
44 |
45 | ### Install NodeJS 12.22.x
46 |
47 | ```console
48 | foo@pop-os:~$ curl -sL https://deb.nodesource.com/setup_12.x -o nodesource_setup.sh
49 | foo@pop-os:~$ sudo bash nodesource_setup.sh
50 | foo@pop-os:~$ sudo apt install nodejs -y
51 | ```
52 |
53 | ### Check version
54 |
55 | ```console
56 | foo@pop-os:~$ nodejs -v
57 | v12.22.1
58 | foo@pop-os:~$ npm -v
59 | 6.14.12
60 | ```
61 |
62 | ### Install Jest, Babel, and ESLint
63 |
64 | ```console
65 | foo@pop-os:~$ npm install --save-dev jest
66 | foo@pop-os:~$ npm install --save-dev babel-jest @babel/core @babel/preset-env
67 | foo@pop-os:~$ npm install --save-dev eslint
68 | ```
69 |
70 | ---
71 |
72 | ## Files:card_file_box:
73 |
74 | ### [0. You used to attend a place like this at some point](./0-classroom.js)
75 |
76 | ### [1. Let's make some classrooms](./1-make_classrooms.js)
77 |
78 | ### [2. A Course, Getters, and Setters](./2-hbtn_course.js)
79 |
80 | ### [3. Methods, static methods, computed methods names..... MONEY](./3-currency.js)
81 |
82 | ### [4. Pricing](./4-pricing.js)
83 |
84 | ### [5. A Building](./5-building.js)
85 |
86 | ### [6. Inheritance](./6-sky_high.js)
87 |
88 | ### [7. Airport](./7-airport.js)
89 |
90 | ### [8. Primitive - Holberton Class](./8-hbtn_class.js)
91 |
92 | ### [9. Hoisting](./9-hoisting.js)
93 |
94 | ### [10. Vroom](./10-car.js)
95 |
96 | ### [11. EVcar](./100-evcar.js)
97 |
98 | ---
99 |
100 | ## Author
101 |
102 | - **Joseph Mahiuha** (@Mahiuha) - [
](https://mahiuha.github.io/josephmahiuha/)
103 | [
](https://twitter.com/Joseph_Mahiuha)
104 | [
](https://www.linkedin.com/in/joseph-mahiuha-498a52162/)
105 | [
](https://github.com/Mahiuha)
106 |
--------------------------------------------------------------------------------
/0x02-ES6_classes/babel.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | presets: [
3 | [
4 | '@babel/preset-env',
5 | {
6 | targets: {
7 | node: 'current',
8 | },
9 | },
10 | ],
11 | ],
12 | };
13 |
--------------------------------------------------------------------------------
/0x02-ES6_classes/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "scripts": {
3 | "lint": "./node_modules/.bin/eslint",
4 | "check-lint": "lint [0-9]*.js",
5 | "dev": "npx babel-node",
6 | "test": "jest",
7 | "full-test": "./node_modules/.bin/eslint [0-9]*.js && jest"
8 | },
9 | "devDependencies": {
10 | "@babel/core": "^7.6.0",
11 | "@babel/preset-env": "^7.6.0",
12 | "@babel/node": "^7.8.0",
13 | "eslint": "^6.4.0",
14 | "eslint-config-airbnb-base": "^14.0.0",
15 | "eslint-plugin-import": "^2.18.2",
16 | "eslint-plugin-jest": "^22.17.0",
17 | "jest": "^24.9.0"
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/0x03-ES6_data_manipulation/.eslintrc.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | env: {
3 | browser: false,
4 | es6: true,
5 | jest: true,
6 | },
7 | extends: [
8 | 'airbnb-base',
9 | 'plugin:jest/all',
10 | ],
11 | globals: {
12 | Atomics: 'readonly',
13 | SharedArrayBuffer: 'readonly',
14 | },
15 | parserOptions: {
16 | ecmaVersion: 2018,
17 | sourceType: 'module',
18 | },
19 | plugins: ['jest'],
20 | rules: {
21 | 'max-classes-per-file': 'off',
22 | 'no-underscore-dangle': 'off',
23 | 'no-console': 'off',
24 | 'no-shadow': 'off',
25 | 'no-restricted-syntax': [
26 | 'error',
27 | 'LabeledStatement',
28 | 'WithStatement',
29 | ],
30 | },
31 | overrides:[
32 | {
33 | files: ['*.js'],
34 | excludedFiles: 'babel.config.js',
35 | }
36 | ]
37 | };
38 |
--------------------------------------------------------------------------------
/0x03-ES6_data_manipulation/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 | /.pnp
6 | .pnp.js
7 |
8 | # testing
9 | /coverage
10 |
11 | # production
12 | /build
13 |
14 | # misc
15 | .DS_Store
16 | .env.local
17 | .env.development.local
18 | .env.test.local
19 | .env.production.local
20 |
21 | npm-debug.log*
22 | yarn-debug.log*
23 | yarn-error.log*
24 | nodesource_setup.sh
25 | *.swp
26 |
27 |
--------------------------------------------------------------------------------
/0x03-ES6_data_manipulation/0-get_list_students.js:
--------------------------------------------------------------------------------
1 | export default function getListStudents() {
2 | return [
3 | { id: 1, firstName: 'Guillaume', location: 'San Francisco' },
4 | { id: 2, firstName: 'James', location: 'Columbia' },
5 | { id: 5, firstName: 'Serena', location: 'San Francisco' },
6 | ];
7 | }
8 |
--------------------------------------------------------------------------------
/0x03-ES6_data_manipulation/0-main.js:
--------------------------------------------------------------------------------
1 | import getListStudents from './0-get_list_students';
2 |
3 | console.log(getListStudents());
4 |
--------------------------------------------------------------------------------
/0x03-ES6_data_manipulation/1-get_list_student_ids.js:
--------------------------------------------------------------------------------
1 | export default function getListStudentIds(arr) {
2 | if (!Array.isArray(arr)) {
3 | return [];
4 | }
5 | return arr.map((student) => student.id);
6 | }
7 |
--------------------------------------------------------------------------------
/0x03-ES6_data_manipulation/1-main.js:
--------------------------------------------------------------------------------
1 | import getListStudentsIds from './1-get_list_student_ids';
2 | import getListStudents from './0-get_list_students';
3 |
4 | console.log(getListStudentIds('hello'));
5 | console.log(getListStudentIds(getListStudents()));
6 |
7 |
--------------------------------------------------------------------------------
/0x03-ES6_data_manipulation/10-main.js:
--------------------------------------------------------------------------------
1 | import updateUniqueItems from './10-update_uniq_items';
2 | import groceriesList from './9-groceries_list';
3 |
4 | const map = groceriesList();
5 | console.log(map);
6 |
7 | updateUniqueItems(map);
8 | console.log(map);
9 |
--------------------------------------------------------------------------------
/0x03-ES6_data_manipulation/10-update_uniq_items.js:
--------------------------------------------------------------------------------
1 | export default function updateUniqueItems(items) {
2 | if (!(items instanceof Map)) {
3 | throw new Error('Cannot process');
4 | }
5 | for (const [key, value] of items) {
6 | if (value === 1) {
7 | items.set(key, 100);
8 | }
9 | }
10 | return items;
11 | }
12 |
--------------------------------------------------------------------------------
/0x03-ES6_data_manipulation/100-main.js:
--------------------------------------------------------------------------------
1 | import { queryAPI, weakMap } from './100-weak';
2 |
3 | const endpoint = { protocol: 'http', name: 'getUsers' };
4 | weakMap.get(endpoint);
5 |
6 | queryAPI(endpoint);
7 | console.log(weakMap.get(endpoint));
8 |
9 | queryAPI(endpoint);
10 | console.log(weakMap.get(endpoint));
11 |
12 | queryAPI(endpoint);
13 | queryAPI(endpoint);
14 | queryAPI(endpoint);
15 | queryAPI(endpoint);
16 |
--------------------------------------------------------------------------------
/0x03-ES6_data_manipulation/100-weak.js:
--------------------------------------------------------------------------------
1 | export const weakMap = new WeakMap();
2 |
3 | export function queryAPI(endpoint) {
4 | let called = weakMap.get(endpoint) || 0;
5 |
6 | called += 1;
7 |
8 | weakMap.set(endpoint, called);
9 |
10 | if (called >= 5) {
11 | throw Error('Endpoint load is high');
12 | }
13 |
14 | return called;
15 | }
16 |
--------------------------------------------------------------------------------
/0x03-ES6_data_manipulation/2-get_students_by_loc.js:
--------------------------------------------------------------------------------
1 | export default function getStudentsByLocation(arr, city) {
2 | return arr.filter((student) => student.location === city);
3 | }
4 |
--------------------------------------------------------------------------------
/0x03-ES6_data_manipulation/2-main.js:
--------------------------------------------------------------------------------
1 | import getListStudents from './0-get_list_students';
2 | import getStudentsByLocation from './2-get_students_by_loc';
3 |
4 | const students = getListStudents();
5 |
6 | console.log(getStudentsByLocation(students, 'San Francisco'));
7 |
--------------------------------------------------------------------------------
/0x03-ES6_data_manipulation/3-get_ids_sum.js:
--------------------------------------------------------------------------------
1 | export default function getStudentIdsSum(arr) {
2 | return arr.reduce((acc, student) => acc + student.id, 0);
3 | }
4 |
5 |
--------------------------------------------------------------------------------
/0x03-ES6_data_manipulation/3-main.js:
--------------------------------------------------------------------------------
1 | import getListStudents from './0-get_list_students';
2 | import getStudentIdsSum from './3-get_ids_sum';
3 |
4 | const students = getListStudents();
5 | const value = getStudentIdsSum(students);
6 |
7 | console.log(value);
8 |
--------------------------------------------------------------------------------
/0x03-ES6_data_manipulation/4-main.js:
--------------------------------------------------------------------------------
1 | import getListStudents from './0-get_list_students';
2 | import updateStudentGradeByCity from './4-update_grade_by_city';
3 |
4 | console.log(updateStudentGradeByCity(getListStudents(), 'San Francisco', [{ studentID: 5, grade: 97 }, { studentId: 1, grade: 86 }]));
5 |
6 | console.log(updateStudentGradeByCity(getListStudents(), 'San Francisco', [{ studentId: 5, grade: 97 }]));
7 |
--------------------------------------------------------------------------------
/0x03-ES6_data_manipulation/4-update_grade_by_city.js:
--------------------------------------------------------------------------------
1 | export default function updateStudentGradeByCity(arr, city, newGrades) {
2 | return arr
3 | .filter(student => student.location === city)
4 | .map(student => {
5 | let grade = newGrades.find(g => g.studentId === student.id);
6 | return { ...student, grade: (grade && grade.grade) || 'N/A' };
7 | });
8 | }
9 |
10 |
--------------------------------------------------------------------------------
/0x03-ES6_data_manipulation/5-main.js:
--------------------------------------------------------------------------------
1 | import createInt8TypedArray from './5-typed_arrays';
2 |
3 | console.log(createInt8TypedArray(10, 2, 89));
4 |
--------------------------------------------------------------------------------
/0x03-ES6_data_manipulation/5-typed_arrays.js:
--------------------------------------------------------------------------------
1 | export default function createInt8TypedArray(length, position, value) {
2 | if (position >= length) {
3 | throw new Error('Position outside range');
4 | }
5 |
6 | const buffer = new ArrayBuffer(length);
7 | const view = new DataView(buffer);
8 | view.setInt8(position, value);
9 | return view;
10 | }
11 |
--------------------------------------------------------------------------------
/0x03-ES6_data_manipulation/6-main.js:
--------------------------------------------------------------------------------
1 | import setFromArray from './6-set';
2 |
3 | console.log(setFromArray([12, 32, 15, 78, 98, 15]));
4 |
--------------------------------------------------------------------------------
/0x03-ES6_data_manipulation/6-set.js:
--------------------------------------------------------------------------------
1 | export default function setFromArray(arr) {
2 | return new Set(arr);
3 | }
4 |
--------------------------------------------------------------------------------
/0x03-ES6_data_manipulation/7-has_array_values.js:
--------------------------------------------------------------------------------
1 | export default function hasValuesFromArray(s, arr) {
2 | for (const i of arr) {
3 | if (!s.has(i)) {
4 | return false;
5 | }
6 | }
7 | return true;
8 | }
9 |
--------------------------------------------------------------------------------
/0x03-ES6_data_manipulation/7-main.js:
--------------------------------------------------------------------------------
1 | import hasValuesFromArray from './7-has_array_values';
2 |
3 | console.log(hasValuesFromArray(new Set([1, 2, 3, 4, 5]), [1]));
4 | console.log(hasValuesFromArray(new Set([1, 2, 3, 4, 5]), [10]));
5 | console.log(hasValuesFromArray(new Set([1, 2, 3, 4, 5]), [1, 10]));
6 |
--------------------------------------------------------------------------------
/0x03-ES6_data_manipulation/8-clean_set.js:
--------------------------------------------------------------------------------
1 | export default function cleanSet(set, startString) {
2 | if (!startString || !startString.length || typeof startString !== 'string') return '';
3 |
4 | let finalString = '';
5 | set.forEach((element) => {
6 | if (element && element.startsWith(startString)) finalString += `${element.slice(startString.length)}-`;
7 | });
8 |
9 | return finalString.slice(0, finalString.length - 1);
10 | }
11 |
--------------------------------------------------------------------------------
/0x03-ES6_data_manipulation/8-main.js:
--------------------------------------------------------------------------------
1 | import cleanSet from './8-clean_set';
2 |
3 | console.log(cleanSet(new Set(['bonjovi', 'bonaparte', 'bonappetit', 'banana']), 'bon'));
4 | console.log(cleanSet(new Set(['bonjovi', 'bonaparte', 'bonappetit', 'banana']), ''));
5 |
--------------------------------------------------------------------------------
/0x03-ES6_data_manipulation/9-groceries_list.js:
--------------------------------------------------------------------------------
1 | export default function groceriesList() {
2 | return new Map([
3 | ['Apples', 10],
4 | ['Tomatoes', 10],
5 | ['Pasta', 1],
6 | ['Rice', 1],
7 | ['Banana', 5],
8 | ]);
9 | }
10 |
--------------------------------------------------------------------------------
/0x03-ES6_data_manipulation/9-main.js:
--------------------------------------------------------------------------------
1 | import groceriesList from './9-groceries_list';
2 |
3 | console.log(groceriesList());
4 |
--------------------------------------------------------------------------------
/0x03-ES6_data_manipulation/README.md:
--------------------------------------------------------------------------------
1 | # 0x11. ES6 data manipulation
2 |
3 | ## Description:bulb:
4 |
5 | Array... Array everywhere
6 |
7 | - How to use map, filter and reduce on arrays
8 | - Typed arrays
9 | - The Set, Map, and Weak link data structures
10 |
11 | ## Technologies & Tools:computer:
12 |
13 | [](https://jestjs.io/)
14 | [](https://git-scm.com/)
15 | [](https://ubuntu.com/)
16 | [](https://babeljs.io/)
17 | [](https://developer.mozilla.org/en-US/docs/Web/javascript)
18 | [](https://www.gnu.org/software/bash/)
19 | [](https://nodejs.org/en/)
20 | [](https://www.vim.org/)
21 | [](https://www.vagrantup.com/)
22 | [](https://code.visualstudio.com/)
23 | [](https://eslint.org/)
24 | [](https://github.com/)
25 |
26 | ---
27 |
28 | ## Resources:books:
29 |
30 | Read or watch:
31 |
32 | - [Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)
33 | - [Typed Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Typed_arrays)
34 | - [Set Data Structure](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
35 | - [Map Data Structure](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)
36 | - [WeakMap](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap)
37 |
38 | ---
39 |
40 | ## Requirements:hammer:
41 |
42 | - Ubuntu 18.04 LTS using NodeJS 12.22.x
43 | - Jest Testing Framework
44 | - ESLint
45 |
46 | ### Install NodeJS 12.22.x
47 |
48 | ```console
49 | foo@pop-os:~$ curl -sL https://deb.nodesource.com/setup_12.x -o nodesource_setup.sh
50 | foo@pop-os:~$ sudo bash nodesource_setup.sh
51 | foo@pop-os:~$ sudo apt install nodejs -y
52 | ```
53 |
54 | ### Check version
55 |
56 | ```console
57 | foo@pop-os:~$ nodejs -v
58 | v12.22.1
59 | foo@pop-os:~$ npm -v
60 | 6.14.12
61 | ```
62 |
63 | ### Install Jest, Babel, and ESLint
64 |
65 | ```console
66 | foo@pop-os:~$ npm install --save-dev jest
67 | foo@pop-os:~$ npm install --save-dev babel-jest @babel/core @babel/preset-env
68 | foo@pop-os:~$ npm install --save-dev eslint
69 | foo@pop-os:~$ npm install
70 | ```
71 |
72 | ---
73 |
74 | ## Files:card_file_box:
75 |
76 | ### [0. Basic list of objects](./0-get_list_students.js)
77 |
78 | ### [1. More mapping](./1-get_list_student_ids.js)
79 |
80 | ### [2. Filter](./2-get_students_by_loc.js)
81 |
82 | ### [3. Reduce](./3-get_ids_sum.js)
83 |
84 | ### [4. Combine](./4-update_grade_by_city.js)
85 |
86 | ### [5. Typed Arrays](./5-typed_arrays.js)
87 |
88 | ### [6. Set data structure](./6-set.js)
89 |
90 | ### [7. More set data structure](./7-has_array_values.js)
91 |
92 | ### [8. Clean set](./8-clean_set.js)
93 |
94 | ### [9. Map data structure](./9-groceries_list.js)
95 |
96 | ### [10. More map data structure](./10-update_uniq_items.js)
97 |
98 | ### [11. Weak link data structure](./100-weak.js)
99 |
100 | ---
101 |
102 | ## Author
103 |
104 | - **Joseph Mahiuha** (@Mahiuha) - [
](https://mahiuha.github.io/josephmahiuha/)
105 | [
](https://twitter.com/Joseph_Mahiuha)
106 | [
](https://www.linkedin.com/in/joseph-mahiuha-498a52162/)
107 | [
](https://github.com/Mahiuha)
108 |
--------------------------------------------------------------------------------
/0x03-ES6_data_manipulation/babel.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | presets: [
3 | [
4 | '@babel/preset-env',
5 | {
6 | targets: {
7 | node: 'current',
8 | },
9 | },
10 | ],
11 | ],
12 | };
13 |
--------------------------------------------------------------------------------
/0x03-ES6_data_manipulation/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "scripts": {
3 | "lint": "./node_modules/.bin/eslint",
4 | "check-lint": "lint [0-9]*.js",
5 | "dev": "npx babel-node",
6 | "test": "jest",
7 | "full-test": "./node_modules/.bin/eslint [0-9]*.js && jest"
8 | },
9 | "devDependencies": {
10 | "@babel/core": "^7.6.0",
11 | "@babel/node": "^7.8.0",
12 | "@babel/preset-env": "^7.6.0",
13 | "eslint": "^6.4.0",
14 | "eslint-config-airbnb-base": "^14.0.0",
15 | "eslint-plugin-import": "^2.18.2",
16 | "eslint-plugin-jest": "^22.17.0",
17 | "jest": "^24.9.0"
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/0x04-TypeScript/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 | /.pnp
6 | .pnp.js
7 |
8 | # testing
9 | /coverage
10 |
11 | # production
12 | /build
13 |
14 | # misc
15 | .DS_Store
16 | .env.local
17 | .env.development.local
18 | .env.test.local
19 | .env.production.local
20 |
21 | npm-debug.log*
22 | yarn-debug.log*
23 | yarn-error.log*
24 | nodesource_setup.sh
25 | *.swp
26 |
27 |
--------------------------------------------------------------------------------
/0x04-TypeScript/README.md:
--------------------------------------------------------------------------------
1 | # 0x04 TypeScript
2 |
--------------------------------------------------------------------------------
/0x04-TypeScript/task_0/.eslintrc.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | parser: '@typescript-eslint/parser',
3 | extends: [
4 | 'plugin:@typescript-eslint/recommended', // Uses the recommended rules from @typescript-eslint/eslint-plugin
5 | ],
6 | parserOptions: {
7 | ecmaVersion: 2018,
8 | sourceType: 'module',
9 | },
10 | rules: {
11 | },
12 | };
13 |
--------------------------------------------------------------------------------
/0x04-TypeScript/task_0/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 | /.pnp
6 | .pnp.js
7 |
8 | # testing
9 | /coverage
10 |
11 | # production
12 | /build
13 |
14 | # misc
15 | .DS_Store
16 | .env.local
17 | .env.development.local
18 | .env.test.local
19 | .env.production.local
20 |
21 | npm-debug.log*
22 | yarn-debug.log*
23 | yarn-error.log*
24 | nodesource_setup.sh
25 | *.swp
26 |
--------------------------------------------------------------------------------
/0x04-TypeScript/task_0/js/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 | /.pnp
6 | .pnp.js
7 |
8 | # testing
9 | /coverage
10 |
11 | # production
12 | /build
13 |
14 | # misc
15 | .DS_Store
16 | .env.local
17 | .env.development.local
18 | .env.test.local
19 | .env.production.local
20 |
21 | npm-debug.log*
22 | yarn-debug.log*
23 | yarn-error.log*
24 | nodesource_setup.sh
25 | *.swp
26 |
--------------------------------------------------------------------------------
/0x04-TypeScript/task_0/js/main.ts:
--------------------------------------------------------------------------------
1 | interface Student {
2 | firstName: string;
3 | lastName: string;
4 | age: number;
5 | location: string;
6 | }
7 |
8 | const student1: Student = {
9 | firstName: "John",
10 | lastName: "Doe",
11 | age: 25,
12 | location: "New York"
13 | };
14 |
15 | const student2: Student = {
16 | firstName: "Jane",
17 | lastName: "Doe",
18 | age: 23,
19 | location: "London"
20 | };
21 |
22 | const studentsList: Student[] = [student1, student2];
23 |
24 | function renderTable() {
25 | const table = document.createElement("table");
26 | studentsList.forEach(student => {
27 | const row = table.insertRow();
28 | const firstNameCell = row.insertCell();
29 | firstNameCell.innerHTML = student.firstName;
30 | const locationCell = row.insertCell();
31 | locationCell.innerHTML = student.location;
32 | });
33 | document.body.appendChild(table);
34 | }
35 |
36 | renderTable();
37 |
38 |
--------------------------------------------------------------------------------
/0x04-TypeScript/task_0/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "typescript_dependencies",
3 | "version": "1.0.0",
4 | "description": "",
5 | "main": "index.js",
6 | "scripts": {
7 | "start-dev": "webpack-dev-server --open",
8 | "build": "webpack",
9 | "test": "jest"
10 | },
11 | "keywords": [],
12 | "author": "",
13 | "license": "ISC",
14 | "devDependencies": {
15 | "@babel/plugin-proposal-export-default-from": "^7.5.2",
16 | "@babel/preset-typescript": "^7.7.2",
17 | "@types/jest": "^24.0.23",
18 | "@typescript-eslint/eslint-plugin": "^2.4.0",
19 | "@typescript-eslint/parser": "^2.4.0",
20 | "clean-webpack-plugin": "^3.0.0",
21 | "fork-ts-checker-webpack-plugin": "^1.5.1",
22 | "html-webpack-plugin": "^3.2.0",
23 | "jest": "^24.9.0",
24 | "source-map": "^0.7.3",
25 | "ts-jest": "^24.1.0",
26 | "ts-loader": "^6.2.0",
27 | "typescript": "^3.6.4",
28 | "webpack": "^4.41.2",
29 | "webpack-cli": "^3.3.9",
30 | "webpack-dev-server": "^3.8.2"
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/0x04-TypeScript/task_0/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "outDir": "./dist/",
4 | "sourceMap": true,
5 | "noImplicitAny": true,
6 | "module": "es6",
7 | "target": "es5",
8 | "allowJs": true,
9 | "moduleResolution": "node"
10 | }
11 | }
12 |
13 |
--------------------------------------------------------------------------------
/0x04-TypeScript/task_0/webpack.config.js:
--------------------------------------------------------------------------------
1 | const path = require("path");
2 | const HtmlWebpackPlugin = require('html-webpack-plugin');
3 | const { CleanWebpackPlugin } = require('clean-webpack-plugin');
4 | const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
5 |
6 | module.exports = {
7 | entry: "./js/main.ts",
8 | devtool: "inline-source-map",
9 | module: {
10 | rules: [
11 | {
12 | test: /\.tsx?$/,
13 | loader: 'ts-loader',
14 | options: {
15 | transpileOnly: true
16 | }
17 | }
18 | ]
19 | },
20 | resolve: {
21 | extensions: [".tsx", ".ts", ".js"]
22 | },
23 | devServer: {
24 | contentBase: "./dist"
25 | },
26 | plugins: [
27 | new ForkTsCheckerWebpackPlugin(),
28 | new CleanWebpackPlugin(),
29 | new HtmlWebpackPlugin({
30 | title: "Development"
31 | })
32 | ],
33 | output: {
34 | filename: "bundle.js",
35 | path: path.resolve(__dirname, "dist")
36 | }
37 | };
38 |
--------------------------------------------------------------------------------
/0x04-TypeScript/task_1/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 | /.pnp
6 | .pnp.js
7 |
8 | # testing
9 | /coverage
10 |
11 | # production
12 | /build
13 |
14 | # misc
15 | .DS_Store
16 | .env.local
17 | .env.development.local
18 | .env.test.local
19 | .env.production.local
20 |
21 | npm-debug.log*
22 | yarn-debug.log*
23 | yarn-error.log*
24 | nodesource_setup.sh
25 | *.swp
26 |
--------------------------------------------------------------------------------
/0x04-TypeScript/task_1/js/main.ts:
--------------------------------------------------------------------------------
1 | interface Teacher {
2 | readonly firstName: string;
3 | readonly lastName: string;
4 | fullTimeEmployee: boolean;
5 | location: string;
6 | yearsOfExperience?: number;
7 | [key: string]: any
8 | }
9 |
10 | interface Directors extends Teacher {
11 | numberOfReports: number;
12 | }
13 |
14 | const teacher1: Teacher = {
15 | firstName: 'Frank',
16 | lastName: 'Donald',
17 | fullTimeEmployee: true,
18 | location: 'New Jersey',
19 | contract: false,
20 | }
21 |
22 | console.log(teacher1);
23 |
24 | const director1: Directors = {
25 | firstName: 'John',
26 | lastName: 'Smith',
27 | location: 'America',
28 | fullTimeEmployee: true,
29 | numberOfReports: 17,
30 | };
31 |
32 | console.log(director1);
33 |
34 | interface printTeacherFunction {
35 | (firstName: string, lastName: string): string;
36 | }
37 |
38 | export const printTeacher: printTeacherFunction = (firstName: string, lastName: string): string => `${firstName[0]}. ${lastName}`;
39 |
40 | console.log(printTeacher('john', 'doe'));
41 |
42 | interface StudentClassInterface {
43 | firstName: string;
44 | lastName: string;
45 | }
46 |
47 | interface StudentClassConstructorInterface {
48 | new(firstName: string, lastName: string): StudentClassInterface;
49 | }
50 |
51 | class StudentClass implements StudentClassInterface {
52 | firstName: string;
53 | lastName: string;
54 |
55 | constructor(firstName: string, lastName: string) {
56 | this.firstName = firstName;
57 | this.lastName = lastName;
58 | }
59 |
60 | workOnHomework(): string {
61 | return 'Currently working';
62 | }
63 |
64 | displayName(): string {
65 | return this.firstName;
66 | }
67 | }
68 |
69 | function createStudent(cStudent: StudentClassConstructorInterface, firstName: string, lastName: string): StudentClassInterface {
70 | return new cStudent(firstName, lastName);
71 | }
72 |
73 | const student1 = createStudent(StudentClass, 'mike', 'tyson');
74 | console.log(student1);
75 |
76 |
--------------------------------------------------------------------------------
/0x04-TypeScript/task_1/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "typescript_dependencies",
3 | "version": "1.0.0",
4 | "description": "",
5 | "main": "index.js",
6 | "scripts": {
7 | "start-dev": "webpack-dev-server --open",
8 | "build": "webpack",
9 | "test": "jest"
10 | },
11 | "keywords": [],
12 | "author": "",
13 | "license": "ISC",
14 | "devDependencies": {
15 | "@babel/plugin-proposal-export-default-from": "^7.5.2",
16 | "@babel/preset-typescript": "^7.7.2",
17 | "@types/jest": "^24.0.23",
18 | "@typescript-eslint/eslint-plugin": "^2.34.0",
19 | "@typescript-eslint/parser": "^2.34.0",
20 | "clean-webpack-plugin": "^3.0.0",
21 | "eslint": "^8.33.0",
22 | "fork-ts-checker-webpack-plugin": "^1.5.1",
23 | "html-webpack-plugin": "^3.2.0",
24 | "jest": "^24.9.0",
25 | "source-map": "^0.7.3",
26 | "ts-jest": "^24.1.0",
27 | "ts-loader": "^6.2.0",
28 | "typescript": "^3.9.10",
29 | "webpack": "^4.41.2",
30 | "webpack-cli": "^3.3.9",
31 | "webpack-dev-server": "^3.8.2"
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/0x04-TypeScript/task_1/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "outDir": "./dist/",
4 | "sourceMap": true,
5 | "noImplicitAny": true,
6 | "module": "es6",
7 | "target": "es5",
8 | "allowJs": true,
9 | "moduleResolution": "node"
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/0x04-TypeScript/task_1/webpack.config.js:
--------------------------------------------------------------------------------
1 | const path = require("path");
2 | const HtmlWebpackPlugin = require('html-webpack-plugin');
3 | const { CleanWebpackPlugin } = require('clean-webpack-plugin');
4 | const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
5 |
6 | module.exports = {
7 | entry: "./js/main.ts",
8 | devtool: "inline-source-map",
9 | module: {
10 | rules: [
11 | {
12 | test: /\.tsx?$/,
13 | loader: 'ts-loader',
14 | options: {
15 | transpileOnly: true
16 | }
17 | }
18 | ]
19 | },
20 | resolve: {
21 | extensions: [".tsx", ".ts", ".js"]
22 | },
23 | devServer: {
24 | contentBase: "./dist"
25 | },
26 | plugins: [
27 | new ForkTsCheckerWebpackPlugin(),
28 | new CleanWebpackPlugin(),
29 | new HtmlWebpackPlugin({
30 | title: "Development"
31 | })
32 | ],
33 | output: {
34 | filename: "bundle.js",
35 | path: path.resolve(__dirname, "dist")
36 | }
37 | };
38 |
--------------------------------------------------------------------------------
/0x04-TypeScript/task_2/js/main.ts:
--------------------------------------------------------------------------------
1 | interface DirectorInterface {
2 | workFromHome(): string;
3 | getCoffeeBreak(): string;
4 | workDirectorTasks(): string;
5 | }
6 |
7 | interface TeacherInterface {
8 | workFromHome(): string;
9 | getCoffeeBreak(): string;
10 | workTeacherTasks(): string;
11 | }
12 |
13 | class Director implements DirectorInterface {
14 | workFromHome(): string {
15 | return 'Working from home';
16 | }
17 |
18 | getCoffeeBreak(): string {
19 | return 'Getting a coffee break';
20 | }
21 |
22 | workDirectorTasks(): string {
23 | return 'Getting to director tasks';
24 | }
25 | }
26 |
27 | class Teacher implements TeacherInterface {
28 | workFromHome(): string {
29 | return 'Cannot work from home';
30 | }
31 |
32 | getCoffeeBreak(): string {
33 | return 'Cannot have a break';
34 | }
35 |
36 | workTeacherTasks(): string {
37 | return 'Getting to work';
38 | }
39 | }
40 |
41 | function createEmployee(salary: number | string): Teacher | Director {
42 | return typeof salary === 'number' && salary < 500 ? new Teacher() : new Director();
43 | }
44 |
45 | console.log(createEmployee(200));
46 |
47 | console.log(createEmployee(1000));
48 |
49 | console.log(createEmployee('$500'));
50 |
51 | const isDirector = (employee: Teacher | Director): boolean => employee instanceof Director;
52 |
53 | const executeWork = (employee: Teacher | Director): string => {
54 | let res;
55 | isDirector(employee) ? res = (employee as Director).workDirectorTasks() : res = (employee as Teacher).workTeacherTasks();
56 | return res;
57 | };
58 |
59 | console.log(executeWork(createEmployee(200)));
60 |
61 | console.log(executeWork(createEmployee(1000)));
62 |
63 | type Subjects = 'Math' | 'History';
64 |
65 | const teachClass = (todayClass: Subjects): string => todayClass === 'Math' ? 'Teaching Math' : 'Teaching History';
66 |
67 | console.log(teachClass('Math'));
68 |
69 | console.log(teachClass('History'));
70 |
71 |
--------------------------------------------------------------------------------
/0x04-TypeScript/task_3/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 | /.pnp
6 | .pnp.js
7 |
8 | # testing
9 | /coverage
10 |
11 | # production
12 | /build
13 |
14 | # misc
15 | .DS_Store
16 | .env.local
17 | .env.development.local
18 | .env.test.local
19 | .env.production.local
20 |
21 | npm-debug.log*
22 | yarn-debug.log*
23 | yarn-error.log*
24 | nodesource_setup.sh
25 | *.swp
26 |
--------------------------------------------------------------------------------
/0x04-TypeScript/task_3/dist/bundle.js:
--------------------------------------------------------------------------------
1 | !function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=0)}([function(e,t,r){"use strict";r.r(t);var n,o=function(){return(o=Object.assign||function(e){for(var t,r=1,n=arguments.length;r
2 |
3 |
4 |
5 | Development
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/0x04-TypeScript/task_3/js/crud.d.ts:
--------------------------------------------------------------------------------
1 | import { RowID, RowElement } from './interface';
2 |
3 | declare module 'crud' {
4 | export function insertRow(row: RowElement): RowID;
5 | export function deleteRow(rowId: RowID): void;
6 | export function updateRow(rowId: RowID, row: RowElement): RowID;
7 | }
8 |
9 |
--------------------------------------------------------------------------------
/0x04-TypeScript/task_3/js/crud.js:
--------------------------------------------------------------------------------
1 | export function insertRow(row) {
2 | console.log('Insert row', row);
3 | return Math.floor(Math.random() * Math.floor(1000));
4 | }
5 |
6 | export function deleteRow(rowId) {
7 | console.log('Delete row id', rowId);
8 | return;
9 | }
10 |
11 | export function updateRow(rowId, row) {
12 | console.log(`Update row ${rowId}`, row);
13 |
14 | return rowId;
15 | }
16 |
--------------------------------------------------------------------------------
/0x04-TypeScript/task_3/js/interface.ts:
--------------------------------------------------------------------------------
1 | export type RowID = number;
2 |
3 | export interface RowElement {
4 | firstName: string;
5 | lastName: string;
6 | age?: number;
7 | }
8 |
9 |
--------------------------------------------------------------------------------
/0x04-TypeScript/task_3/js/main.ts:
--------------------------------------------------------------------------------
1 | ///
2 | import { RowID, RowElement } from './interface';
3 | import * as CRUD from './crud';
4 |
5 | const row: RowElement = { firstName: 'Guillaume', lastName: 'Salva' };
6 | const newRowID: RowID = CRUD.insertRow(row);
7 |
8 | const updatedRow: RowElement = { ...row, age: 23 };
9 | CRUD.updateRow(newRowID, updatedRow);
10 |
11 | CRUD.deleteRow(newRowID);
12 |
13 |
--------------------------------------------------------------------------------
/0x04-TypeScript/task_3/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "typescript_dependencies",
3 | "version": "1.0.0",
4 | "description": "",
5 | "main": "index.js",
6 | "scripts": {
7 | "start-dev": "webpack-dev-server --open",
8 | "build": "webpack",
9 | "test": "jest"
10 | },
11 | "keywords": [],
12 | "author": "",
13 | "license": "ISC",
14 | "devDependencies": {
15 | "@babel/plugin-proposal-export-default-from": "^7.5.2",
16 | "@babel/preset-typescript": "^7.7.2",
17 | "@types/jest": "^24.0.23",
18 | "@typescript-eslint/eslint-plugin": "^2.34.0",
19 | "@typescript-eslint/parser": "^2.34.0",
20 | "clean-webpack-plugin": "^3.0.0",
21 | "eslint": "^8.33.0",
22 | "fork-ts-checker-webpack-plugin": "^1.5.1",
23 | "html-webpack-plugin": "^3.2.0",
24 | "jest": "^24.9.0",
25 | "source-map": "^0.7.3",
26 | "ts-jest": "^24.1.0",
27 | "ts-loader": "^6.2.0",
28 | "typescript": "^3.9.10",
29 | "webpack": "^4.41.2",
30 | "webpack-cli": "^3.3.9",
31 | "webpack-dev-server": "^3.8.2"
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/0x04-TypeScript/task_3/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "outDir": "./dist/",
4 | "sourceMap": true,
5 | "noImplicitAny": true,
6 | "module": "es6",
7 | "target": "es5",
8 | "allowJs": true,
9 | "moduleResolution": "node"
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/0x04-TypeScript/task_3/webpack.config.js:
--------------------------------------------------------------------------------
1 | const path = require("path");
2 | const HtmlWebpackPlugin = require('html-webpack-plugin');
3 | const { CleanWebpackPlugin } = require('clean-webpack-plugin');
4 | const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
5 |
6 | module.exports = {
7 | entry: "./js/main.ts",
8 | devtool: "inline-source-map",
9 | module: {
10 | rules: [
11 | {
12 | test: /\.tsx?$/,
13 | loader: 'ts-loader',
14 | options: {
15 | transpileOnly: true
16 | }
17 | }
18 | ]
19 | },
20 | resolve: {
21 | extensions: [".tsx", ".ts", ".js"]
22 | },
23 | devServer: {
24 | contentBase: "./dist"
25 | },
26 | plugins: [
27 | new ForkTsCheckerWebpackPlugin(),
28 | new CleanWebpackPlugin(),
29 | new HtmlWebpackPlugin({
30 | title: "Development"
31 | })
32 | ],
33 | output: {
34 | filename: "bundle.js",
35 | path: path.resolve(__dirname, "dist")
36 | }
37 | };
38 |
--------------------------------------------------------------------------------
/0x04-TypeScript/task_4/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 | /.pnp
6 | .pnp.js
7 |
8 | # testing
9 | /coverage
10 |
11 | # production
12 | /build
13 |
14 | # misc
15 | .DS_Store
16 | .env.local
17 | .env.development.local
18 | .env.test.local
19 | .env.production.local
20 |
21 | npm-debug.log*
22 | yarn-debug.log*
23 | yarn-error.log*
24 | nodesource_setup.sh
25 | *.swp
26 |
--------------------------------------------------------------------------------
/0x04-TypeScript/task_4/js/main.ts:
--------------------------------------------------------------------------------
1 | import { Subjects } from "./Subjects";
2 |
3 | export const cpp = new Subjects.Cpp();
4 | export const java = new Subjects.Java();
5 | export const react = new Subjects.React();
6 |
7 | export const cTeacher: Subjects.Teacher = {
8 | firstName: "John",
9 | lastName: "Doe",
10 | experienceTeachingC: 10,
11 | };
12 |
13 | console.log("C++");
14 | cpp.setTeacher(cTeacher);
15 | console.log(cpp.getRequirements());
16 | console.log(cpp.getAvailableTeacher());
17 |
18 | console.log("Java");
19 | java.setTeacher(cTeacher);
20 | console.log(java.getRequirements());
21 | console.log(java.getAvailableTeacher());
22 |
23 | console.log("React");
24 | react.setTeacher(cTeacher);
25 | console.log(react.getRequirements());
26 | console.log(react.getAvailableTeacher());
27 |
28 |
--------------------------------------------------------------------------------
/0x04-TypeScript/task_4/js/subjects/Cpp.ts:
--------------------------------------------------------------------------------
1 | namespace Subjects {
2 | export interface Teacher {
3 | experienceTeachingC?: number;
4 | }
5 |
6 | export class Cpp extends Subject {
7 | getRequirements(): string {
8 | return "Here is the list of requirements for Cpp";
9 | }
10 |
11 | getAvailableTeacher(): string {
12 | if (this.teacher?.experienceTeachingC) {
13 | return `Available Teacher: ${this.teacher.firstName}`;
14 | } else {
15 | return "No available teacher";
16 | }
17 | }
18 | }
19 | }
20 |
21 |
--------------------------------------------------------------------------------
/0x04-TypeScript/task_4/js/subjects/Java.ts:
--------------------------------------------------------------------------------
1 | namespace Subjects {
2 | export interface Teacher {
3 | experienceTeachingJava?: number;
4 | }
5 |
6 | export class Java extends Subject {
7 | getRequirements(): string {
8 | return "Here is the list of requirements for Java";
9 | }
10 |
11 | getAvailableTeacher(): string {
12 | if (this.teacher?.experienceTeachingJava) {
13 | return `Available Teacher: ${this.teacher.firstName}`;
14 | } else {
15 | return "No available teacher";
16 | }
17 | }
18 | }
19 | }
20 |
21 |
--------------------------------------------------------------------------------
/0x04-TypeScript/task_4/js/subjects/React.ts:
--------------------------------------------------------------------------------
1 | namespace Subjects {
2 | export interface Teacher {
3 | experienceTeachingReact?: number;
4 | }
5 |
6 | export class React extends Subject {
7 | getRequirements(): string {
8 | return "Here is the list of requirements for React";
9 | }
10 |
11 | getAvailableTeacher(): string {
12 | if (this.teacher?.experienceTeachingReact) {
13 | return `Available Teacher: ${this.teacher.firstName}`;
14 | } else {
15 | return "No available teacher";
16 | }
17 | }
18 | }
19 | }
20 |
21 |
--------------------------------------------------------------------------------
/0x04-TypeScript/task_4/js/subjects/Subject.ts:
--------------------------------------------------------------------------------
1 | namespace Subjects {
2 | export class Subject {
3 | teacher: Teacher;
4 |
5 | setTeacher(teacher: Teacher) {
6 | this.teacher = teacher;
7 | }
8 | }
9 | }
10 |
11 |
--------------------------------------------------------------------------------
/0x04-TypeScript/task_4/js/subjects/Teacher.ts:
--------------------------------------------------------------------------------
1 | namespace Subjects {
2 | export interface Teacher {
3 | firstName: string;
4 | lastName: string;
5 | }
6 | }
7 |
8 |
--------------------------------------------------------------------------------
/0x04-TypeScript/task_4/package-lock.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "task_4",
3 | "version": "1.0.0",
4 | "lockfileVersion": 1,
5 | "requires": true,
6 | "dependencies": {
7 | "@types/eslint-visitor-keys": {
8 | "version": "1.0.0",
9 | "resolved": "https://registry.npmjs.org/@types/eslint-visitor-keys/-/eslint-visitor-keys-1.0.0.tgz",
10 | "integrity": "sha512-OCutwjDZ4aFS6PB1UZ988C4YgwlBHJd6wCeQqaLdmadZ/7e+w79+hbMUFC1QXDNCmdyoRfAFdm0RypzwR+Qpag==",
11 | "dev": true
12 | },
13 | "@types/json-schema": {
14 | "version": "7.0.11",
15 | "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.11.tgz",
16 | "integrity": "sha512-wOuvG1SN4Us4rez+tylwwwCV1psiNVOkJeM3AUWUNWg/jDQY2+HE/444y5gc+jBmRqASOm2Oeh5c1axHobwRKQ==",
17 | "dev": true
18 | },
19 | "@typescript-eslint/eslint-plugin": {
20 | "version": "2.34.0",
21 | "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-2.34.0.tgz",
22 | "integrity": "sha512-4zY3Z88rEE99+CNvTbXSyovv2z9PNOVffTWD2W8QF5s2prBQtwN2zadqERcrHpcR7O/+KMI3fcTAmUUhK/iQcQ==",
23 | "dev": true,
24 | "requires": {
25 | "@typescript-eslint/experimental-utils": "2.34.0",
26 | "functional-red-black-tree": "^1.0.1",
27 | "regexpp": "^3.0.0",
28 | "tsutils": "^3.17.1"
29 | }
30 | },
31 | "@typescript-eslint/experimental-utils": {
32 | "version": "2.34.0",
33 | "resolved": "https://registry.npmjs.org/@typescript-eslint/experimental-utils/-/experimental-utils-2.34.0.tgz",
34 | "integrity": "sha512-eS6FTkq+wuMJ+sgtuNTtcqavWXqsflWcfBnlYhg/nS4aZ1leewkXGbvBhaapn1q6qf4M71bsR1tez5JTRMuqwA==",
35 | "dev": true,
36 | "requires": {
37 | "@types/json-schema": "^7.0.3",
38 | "@typescript-eslint/typescript-estree": "2.34.0",
39 | "eslint-scope": "^5.0.0",
40 | "eslint-utils": "^2.0.0"
41 | }
42 | },
43 | "@typescript-eslint/parser": {
44 | "version": "2.34.0",
45 | "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-2.34.0.tgz",
46 | "integrity": "sha512-03ilO0ucSD0EPTw2X4PntSIRFtDPWjrVq7C3/Z3VQHRC7+13YB55rcJI3Jt+YgeHbjUdJPcPa7b23rXCBokuyA==",
47 | "dev": true,
48 | "requires": {
49 | "@types/eslint-visitor-keys": "^1.0.0",
50 | "@typescript-eslint/experimental-utils": "2.34.0",
51 | "@typescript-eslint/typescript-estree": "2.34.0",
52 | "eslint-visitor-keys": "^1.1.0"
53 | }
54 | },
55 | "@typescript-eslint/typescript-estree": {
56 | "version": "2.34.0",
57 | "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-2.34.0.tgz",
58 | "integrity": "sha512-OMAr+nJWKdlVM9LOqCqh3pQQPwxHAN7Du8DR6dmwCrAmxtiXQnhHJ6tBNtf+cggqfo51SG/FCwnKhXCIM7hnVg==",
59 | "dev": true,
60 | "requires": {
61 | "debug": "^4.1.1",
62 | "eslint-visitor-keys": "^1.1.0",
63 | "glob": "^7.1.6",
64 | "is-glob": "^4.0.1",
65 | "lodash": "^4.17.15",
66 | "semver": "^7.3.2",
67 | "tsutils": "^3.17.1"
68 | }
69 | },
70 | "balanced-match": {
71 | "version": "1.0.2",
72 | "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz",
73 | "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==",
74 | "dev": true
75 | },
76 | "brace-expansion": {
77 | "version": "1.1.11",
78 | "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
79 | "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
80 | "dev": true,
81 | "requires": {
82 | "balanced-match": "^1.0.0",
83 | "concat-map": "0.0.1"
84 | }
85 | },
86 | "concat-map": {
87 | "version": "0.0.1",
88 | "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
89 | "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==",
90 | "dev": true
91 | },
92 | "debug": {
93 | "version": "4.3.4",
94 | "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",
95 | "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==",
96 | "dev": true,
97 | "requires": {
98 | "ms": "2.1.2"
99 | }
100 | },
101 | "eslint-scope": {
102 | "version": "5.1.1",
103 | "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.1.tgz",
104 | "integrity": "sha512-2NxwbF/hZ0KpepYN0cNbo+FN6XoK7GaHlQhgx/hIZl6Va0bF45RQOOwhLIy8lQDbuCiadSLCBnH2CFYquit5bw==",
105 | "dev": true,
106 | "requires": {
107 | "esrecurse": "^4.3.0",
108 | "estraverse": "^4.1.1"
109 | }
110 | },
111 | "eslint-utils": {
112 | "version": "2.1.0",
113 | "resolved": "https://registry.npmjs.org/eslint-utils/-/eslint-utils-2.1.0.tgz",
114 | "integrity": "sha512-w94dQYoauyvlDc43XnGB8lU3Zt713vNChgt4EWwhXAP2XkBvndfxF0AgIqKOOasjPIPzj9JqgwkwbCYD0/V3Zg==",
115 | "dev": true,
116 | "requires": {
117 | "eslint-visitor-keys": "^1.1.0"
118 | }
119 | },
120 | "eslint-visitor-keys": {
121 | "version": "1.3.0",
122 | "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-1.3.0.tgz",
123 | "integrity": "sha512-6J72N8UNa462wa/KFODt/PJ3IU60SDpC3QXC1Hjc1BXXpfL2C9R5+AU7jhe0F6GREqVMh4Juu+NY7xn+6dipUQ==",
124 | "dev": true
125 | },
126 | "esrecurse": {
127 | "version": "4.3.0",
128 | "resolved": "https://registry.npmjs.org/esrecurse/-/esrecurse-4.3.0.tgz",
129 | "integrity": "sha512-KmfKL3b6G+RXvP8N1vr3Tq1kL/oCFgn2NYXEtqP8/L3pKapUA4G8cFVaoF3SU323CD4XypR/ffioHmkti6/Tag==",
130 | "dev": true,
131 | "requires": {
132 | "estraverse": "^5.2.0"
133 | },
134 | "dependencies": {
135 | "estraverse": {
136 | "version": "5.3.0",
137 | "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-5.3.0.tgz",
138 | "integrity": "sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA==",
139 | "dev": true
140 | }
141 | }
142 | },
143 | "estraverse": {
144 | "version": "4.3.0",
145 | "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-4.3.0.tgz",
146 | "integrity": "sha512-39nnKffWz8xN1BU/2c79n9nB9HDzo0niYUqx6xyqUnyoAnQyyWpOTdZEeiCch8BBu515t4wp9ZmgVfVhn9EBpw==",
147 | "dev": true
148 | },
149 | "fs.realpath": {
150 | "version": "1.0.0",
151 | "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
152 | "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==",
153 | "dev": true
154 | },
155 | "functional-red-black-tree": {
156 | "version": "1.0.1",
157 | "resolved": "https://registry.npmjs.org/functional-red-black-tree/-/functional-red-black-tree-1.0.1.tgz",
158 | "integrity": "sha512-dsKNQNdj6xA3T+QlADDA7mOSlX0qiMINjn0cgr+eGHGsbSHzTabcIogz2+p/iqP1Xs6EP/sS2SbqH+brGTbq0g==",
159 | "dev": true
160 | },
161 | "glob": {
162 | "version": "7.2.3",
163 | "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz",
164 | "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==",
165 | "dev": true,
166 | "requires": {
167 | "fs.realpath": "^1.0.0",
168 | "inflight": "^1.0.4",
169 | "inherits": "2",
170 | "minimatch": "^3.1.1",
171 | "once": "^1.3.0",
172 | "path-is-absolute": "^1.0.0"
173 | }
174 | },
175 | "inflight": {
176 | "version": "1.0.6",
177 | "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz",
178 | "integrity": "sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==",
179 | "dev": true,
180 | "requires": {
181 | "once": "^1.3.0",
182 | "wrappy": "1"
183 | }
184 | },
185 | "inherits": {
186 | "version": "2.0.4",
187 | "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
188 | "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==",
189 | "dev": true
190 | },
191 | "is-extglob": {
192 | "version": "2.1.1",
193 | "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz",
194 | "integrity": "sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==",
195 | "dev": true
196 | },
197 | "is-glob": {
198 | "version": "4.0.3",
199 | "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz",
200 | "integrity": "sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==",
201 | "dev": true,
202 | "requires": {
203 | "is-extglob": "^2.1.1"
204 | }
205 | },
206 | "lodash": {
207 | "version": "4.17.21",
208 | "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
209 | "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==",
210 | "dev": true
211 | },
212 | "lru-cache": {
213 | "version": "6.0.0",
214 | "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz",
215 | "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==",
216 | "dev": true,
217 | "requires": {
218 | "yallist": "^4.0.0"
219 | }
220 | },
221 | "minimatch": {
222 | "version": "3.1.2",
223 | "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz",
224 | "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==",
225 | "dev": true,
226 | "requires": {
227 | "brace-expansion": "^1.1.7"
228 | }
229 | },
230 | "ms": {
231 | "version": "2.1.2",
232 | "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
233 | "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==",
234 | "dev": true
235 | },
236 | "once": {
237 | "version": "1.4.0",
238 | "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
239 | "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==",
240 | "dev": true,
241 | "requires": {
242 | "wrappy": "1"
243 | }
244 | },
245 | "path-is-absolute": {
246 | "version": "1.0.1",
247 | "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
248 | "integrity": "sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg==",
249 | "dev": true
250 | },
251 | "regexpp": {
252 | "version": "3.2.0",
253 | "resolved": "https://registry.npmjs.org/regexpp/-/regexpp-3.2.0.tgz",
254 | "integrity": "sha512-pq2bWo9mVD43nbts2wGv17XLiNLya+GklZ8kaDLV2Z08gDCsGpnKn9BFMepvWuHCbyVvY7J5o5+BVvoQbmlJLg==",
255 | "dev": true
256 | },
257 | "semver": {
258 | "version": "7.3.8",
259 | "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.8.tgz",
260 | "integrity": "sha512-NB1ctGL5rlHrPJtFDVIVzTyQylMLu9N9VICA6HSFJo8MCGVTMW6gfpicwKmmK/dAjTOrqu5l63JJOpDSrAis3A==",
261 | "dev": true,
262 | "requires": {
263 | "lru-cache": "^6.0.0"
264 | }
265 | },
266 | "tslib": {
267 | "version": "1.14.1",
268 | "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz",
269 | "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==",
270 | "dev": true
271 | },
272 | "tsutils": {
273 | "version": "3.21.0",
274 | "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-3.21.0.tgz",
275 | "integrity": "sha512-mHKK3iUXL+3UF6xL5k0PEhKRUBKPBCv/+RkEOpjRWxxx27KKRBmmA60A9pgOUvMi8GKhRMPEmjBRPzs2W7O1OA==",
276 | "dev": true,
277 | "requires": {
278 | "tslib": "^1.8.1"
279 | }
280 | },
281 | "typescript": {
282 | "version": "3.9.10",
283 | "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.9.10.tgz",
284 | "integrity": "sha512-w6fIxVE/H1PkLKcCPsFqKE7Kv7QUwhU8qQY2MueZXWx5cPZdwFupLgKK3vntcK98BtNHZtAF4LA/yl2a7k8R6Q==",
285 | "dev": true
286 | },
287 | "wrappy": {
288 | "version": "1.0.2",
289 | "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
290 | "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==",
291 | "dev": true
292 | },
293 | "yallist": {
294 | "version": "4.0.0",
295 | "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz",
296 | "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==",
297 | "dev": true
298 | }
299 | }
300 | }
301 |
--------------------------------------------------------------------------------
/0x04-TypeScript/task_4/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "task_4",
3 | "version": "1.0.0",
4 | "description": "",
5 | "main": "index.js",
6 | "scripts": {
7 | "test": "echo \"Error: no test specified\" && exit 1"
8 | },
9 | "keywords": [],
10 | "author": "",
11 | "license": "ISC",
12 | "devDependencies": {
13 | "@typescript-eslint/eslint-plugin": "^2.4.0",
14 | "@typescript-eslint/parser": "^2.4.0",
15 | "typescript": "^3.6.4"
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/0x04-TypeScript/task_4/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "outDir": "./dist/",
4 | "sourceMap": true,
5 | "noImplicitAny": true,
6 | "module": "es6",
7 | "target": "es5",
8 | "allowJs": true,
9 | "moduleResolution": "node"
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/0x04-TypeScript/task_5/js/main.ts:
--------------------------------------------------------------------------------
1 | interface MajorCredits {
2 | credits: number;
3 | brand: "MajorCredits";
4 | }
5 |
6 | interface MinorCredits {
7 | credits: number;
8 | brand: "MinorCredits";
9 | }
10 |
11 | function sumMajorCredits(subject1: MajorCredits, subject2: MajorCredits): MajorCredits {
12 | return {
13 | credits: subject1.credits + subject2.credits,
14 | brand: "MajorCredits",
15 | };
16 | }
17 |
18 | function sumMinorCredits(subject1: MinorCredits, subject2: MinorCredits): MinorCredits {
19 | return {
20 | credits: subject1.credits + subject2.credits,
21 | brand: "MinorCredits",
22 | };
23 | }
24 |
25 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Web Stack Specialization - Front-end
2 | 
3 | > Web Stack - Front-end
4 |
5 | ## Description:bulb:
6 | * Advanced HTML/CSS
7 | * Developer Tools
8 | * SCSS
9 | * Flexbox
10 | * Responsive Design
11 | * Accesibility
12 | * Working with Designers
13 | * Design Implementation
14 | * Bootstrap
15 | * Advanced Javascript
16 | * Advanced JQuery
17 | * Cookies & Local Storage
18 | * ES6
19 | * TypeScript
20 | * Webpack
21 | * Building Portfolio Applications
22 |
23 | ## Technologies & Tools:computer:
24 |
25 | 
26 | 
27 | 
28 | 
29 | 
30 | 
31 | 
32 | 
33 | 
34 | 
35 | 
36 | 
37 | 
38 | 
39 | 
40 | 
41 |
42 | ---
43 |
44 | ## Author
45 | * **Joseph Mahiuha** (@Mahiuha) - [
](https://mahiuha.github.io/josephmahiuha/)
46 | [
](https://twitter.com/Joseph_Mahiuha)
47 | [
](https://www.linkedin.com/in/joseph-mahiuha-498a52162/)
48 | [
](https://github.com/Mahiuha)
49 |
--------------------------------------------------------------------------------