├── 0x00-ES6_basic ├── 0-constants.js ├── 1-block-scoped.js ├── 10-loops.js ├── 100-createIteratorObject.js ├── 101-iterateThroughObject.js ├── 11-createEmployeesObject.js ├── 12-createReportObject.js ├── 2-arrow.js ├── 3-default-parameter.js ├── 4-rest-parameter.js ├── 5-spread-operator.js ├── 6-string-interpolation.js ├── 7-getBudgetObject.js ├── 8-getBudgetCurrentYear.js ├── 9-getFullBudget.js ├── README.md └── tests │ ├── 0-main.js │ ├── 1-main.js │ ├── 10-main.js │ ├── 100-main.js │ ├── 101-main.js │ ├── 11-main.js │ ├── 12-main.js │ ├── 2-main.js │ ├── 3-main.js │ ├── 4-main.js │ ├── 5-main.js │ ├── 6-main.js │ ├── 7-main.js │ ├── 8-main.js │ └── 9-main.js ├── 0x01-ES6_promise ├── 0-promise.js ├── 1-promise.js ├── 100-await.js ├── 2-then.js ├── 3-all.js ├── 4-user-promise.js ├── 5-photo-reject.js ├── 6-final-user.js ├── 7-load_balancer.js ├── 8-try.js ├── 9-try.js ├── README.md └── tests │ ├── 0-main.js │ ├── 1-main.js │ ├── 100-main.js │ ├── 2-main.js │ ├── 3-main.js │ ├── 4-main.js │ ├── 5-main.js │ ├── 6-main.js │ ├── 7-main.js │ ├── 8-main.js │ └── 9-main.js ├── 0x02-ES6_classes ├── 0-classroom.js ├── 1-make_classrooms.js ├── 10-car.js ├── 100-evcar.js ├── 2-hbtn_course.js ├── 3-currency.js ├── 4-pricing.js ├── 5-building.js ├── 6-sky_high.js ├── 7-airport.js ├── 8-hbtn_class.js ├── 9-hoisting.js ├── README.md └── tests │ ├── 0-main.js │ ├── 1-main.js │ ├── 10-main.js │ ├── 100-main.js │ ├── 2-main.js │ ├── 3-main.js │ ├── 4-main.js │ ├── 5-main.js │ ├── 6-main.js │ ├── 7-main.js │ ├── 8-main.js │ └── 9-main.js ├── 0x03-ES6_data_manipulation ├── 0-get_list_students.js ├── 1-get_list_student_ids.js ├── 10-update_uniq_items.js ├── 100-weak.js ├── 2-get_students_by_loc.js ├── 3-get_ids_sum.js ├── 4-update_grade_by_city.js ├── 5-typed_arrays.js ├── 6-set.js ├── 7-has_array_values.js ├── 8-clean_set.js ├── 9-groceries_list.js ├── README.md └── tests │ ├── 0-main.js │ ├── 1-main.js │ ├── 10-main.js │ ├── 100-main.js │ ├── 2-main.js │ ├── 3-main.js │ ├── 4-main.js │ ├── 5-main.js │ ├── 6-main.js │ ├── 7-main.js │ ├── 8-main.js │ └── 9-main.js ├── 0x04-TypeScript ├── README.md ├── task_0 │ ├── .eslintrc.js │ ├── js │ │ ├── main.js │ │ └── main.ts │ ├── package.json │ ├── tsconfig.json │ └── webpack.config.js ├── task_1 │ ├── js │ │ ├── main.js │ │ └── main.ts │ ├── package.json │ ├── tsconfig.json │ └── webpack.config.js ├── task_2 │ ├── js │ │ └── main.ts │ ├── package.json │ ├── tsconfig.json │ └── webpack.config.js ├── task_3 │ ├── js │ │ ├── crud.d.ts │ │ ├── crud.js │ │ ├── interface.ts │ │ └── main.ts │ ├── package.json │ ├── tsconfig.json │ └── webpack.config.js ├── task_4 │ ├── js │ │ ├── main.ts │ │ └── subjects │ │ │ ├── Cpp.ts │ │ │ ├── Java.ts │ │ │ ├── React.ts │ │ │ ├── Subject.ts │ │ │ └── Teacher.ts │ ├── package.json │ └── tsconfig.json └── task_5 │ ├── js │ └── main.ts │ ├── package.json │ ├── tsconfig.json │ └── webpack.config.js └── README.md /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/1-block-scoped.js: -------------------------------------------------------------------------------- 1 | export default function taskBlock(trueOrFalse) { 2 | const task = false; 3 | const task2 = true; 4 | 5 | if (trueOrFalse) { 6 | return [task, task2]; 7 | } 8 | return [task, task2]; 9 | } 10 | -------------------------------------------------------------------------------- /0x00-ES6_basic/10-loops.js: -------------------------------------------------------------------------------- 1 | export default function appendToEachArrayValue(array, appendString) { 2 | const arr = []; 3 | for (const idx of array) { 4 | const value = idx; 5 | arr.push(appendString + value); 6 | } 7 | 8 | return arr; 9 | } 10 | -------------------------------------------------------------------------------- /0x00-ES6_basic/100-createIteratorObject.js: -------------------------------------------------------------------------------- 1 | export default function createIteratorObject(report) { 2 | let allEmployees = []; 3 | for (const item of Object.values(report.allEmployees)) { 4 | allEmployees = [ 5 | ...allEmployees, 6 | ...item, 7 | ]; 8 | } 9 | return allEmployees; 10 | } 11 | -------------------------------------------------------------------------------- /0x00-ES6_basic/101-iterateThroughObject.js: -------------------------------------------------------------------------------- 1 | export default function iterateThroughObject(reportWithIterator) { 2 | return [...reportWithIterator].join(' | '); 3 | } 4 | -------------------------------------------------------------------------------- /0x00-ES6_basic/11-createEmployeesObject.js: -------------------------------------------------------------------------------- 1 | export default function createEmployeesObject(departmentName, employees) { 2 | return { [departmentName]: [...employees] }; 3 | } 4 | -------------------------------------------------------------------------------- /0x00-ES6_basic/12-createReportObject.js: -------------------------------------------------------------------------------- 1 | export default function createReportObject(employeesList) { 2 | return { 3 | allEmployees: { 4 | ...employeesList, 5 | }, 6 | getNumberOfDepartments: (employeesList) => Object.keys(employeesList).length, 7 | }; 8 | } 9 | -------------------------------------------------------------------------------- /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/3-default-parameter.js: -------------------------------------------------------------------------------- 1 | export default function getSumOfHoods(initialNumber, expansion1989 = 89, expansion2019 = 19) { 2 | return initialNumber + expansion1989 + expansion2019; 3 | } 4 | -------------------------------------------------------------------------------- /0x00-ES6_basic/4-rest-parameter.js: -------------------------------------------------------------------------------- 1 | export default function returnHowManyArguments(...theArgs) { 2 | return theArgs.length; 3 | } 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-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\ 10 | , with a per capita personal income of ${budget.income}. As of 2015, San Francisco \ 11 | proper had a GDP of ${budget.gdp}, and a GDP per capita of ${budget.capita}.`; 12 | } 13 | -------------------------------------------------------------------------------- /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/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 | return budget; 13 | } 14 | -------------------------------------------------------------------------------- /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/README.md: -------------------------------------------------------------------------------- 1 | ## 0x00. ES6 Basics 2 | -------------------------------------------------------------------------------- /0x00-ES6_basic/tests/0-main.js: -------------------------------------------------------------------------------- 1 | import { taskFirst, taskNext } from './0-constants.js'; 2 | 3 | console.log(`${taskFirst()} ${taskNext()}`); 4 | -------------------------------------------------------------------------------- /0x00-ES6_basic/tests/1-main.js: -------------------------------------------------------------------------------- 1 | import taskBlock from './1-block-scoped.js'; 2 | 3 | console.log(taskBlock(true)); 4 | console.log(taskBlock(false)); 5 | -------------------------------------------------------------------------------- /0x00-ES6_basic/tests/10-main.js: -------------------------------------------------------------------------------- 1 | import appendToEachArrayValue from './10-loops.js'; 2 | 3 | console.log(appendToEachArrayValue(['appended', 'fixed', 'displayed'], 'correctly-')); 4 | -------------------------------------------------------------------------------- /0x00-ES6_basic/tests/100-main.js: -------------------------------------------------------------------------------- 1 | import createIteratorObject from "./100-createIteratorObject.js"; 2 | 3 | import createEmployeesObject from './11-createEmployeesObject.js'; 4 | import createReportObject from './12-createReportObject.js'; 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 reportWithIterator) { 16 | console.log(item); 17 | } 18 | -------------------------------------------------------------------------------- /0x00-ES6_basic/tests/101-main.js: -------------------------------------------------------------------------------- 1 | import createEmployeesObject from "./11-createEmployeesObject.js"; 2 | import createReportObject from './12-createReportObject.js'; 3 | import createIteratorObject from './100-createIteratorObject.js'; 4 | import iterateThroughObject from './101-iterateThroughObject.js'; 5 | 6 | 7 | const employees = { 8 | ...createEmployeesObject('engineering', ['Bob', 'Jane']), 9 | ...createEmployeesObject('marketing', ['Sylvie']) 10 | }; 11 | 12 | const report = createReportObject(employees); 13 | const reportWithIterator = createIteratorObject(report); 14 | 15 | console.log(iterateThroughObject(reportWithIterator)); 16 | -------------------------------------------------------------------------------- /0x00-ES6_basic/tests/11-main.js: -------------------------------------------------------------------------------- 1 | import createEmployeesObject from './11-createEmployeesObject.js'; 2 | 3 | console.log(createEmployeesObject("Software", [ "Bob", "Sylvie" ])); 4 | -------------------------------------------------------------------------------- /0x00-ES6_basic/tests/12-main.js: -------------------------------------------------------------------------------- 1 | import createEmployeesObject from './11-createEmployeesObject.js'; 2 | import createReportObject from './12-createReportObject.js'; 3 | 4 | const employees = { 5 | ...createEmployeesObject('engineering', ['Bob', 'Jane']), 6 | ...createEmployeesObject('marketing', ['Sylvie']) 7 | }; 8 | 9 | const report = createReportObject(employees); 10 | console.log(report.allEmployees); 11 | console.log(report.getNumberOfDepartments(report.allEmployees)); 12 | -------------------------------------------------------------------------------- /0x00-ES6_basic/tests/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/tests/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 | -------------------------------------------------------------------------------- /0x00-ES6_basic/tests/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 | -------------------------------------------------------------------------------- /0x00-ES6_basic/tests/5-main.js: -------------------------------------------------------------------------------- 1 | import concatArrays from './5-spread-operator.js'; 2 | 3 | console.log(concatArrays(['a', 'b'], ['c', 'd'], 'Hello')); 4 | -------------------------------------------------------------------------------- /0x00-ES6_basic/tests/6-main.js: -------------------------------------------------------------------------------- 1 | import getSanFranciscoDescription from './6-string-interpolation.js'; 2 | 3 | console.log(getSanFranciscoDescription()); 4 | -------------------------------------------------------------------------------- /0x00-ES6_basic/tests/7-main.js: -------------------------------------------------------------------------------- 1 | import getBudgetObject from './7-getBudgetObject.js'; 2 | 3 | console.log(getBudgetObject(400, 700, 900)); 4 | -------------------------------------------------------------------------------- /0x00-ES6_basic/tests/8-main.js: -------------------------------------------------------------------------------- 1 | import getBudgetForCurrentYear from './8-getBudgetCurrentYear.js'; 2 | 3 | console.log(getBudgetForCurrentYear(2100, 5200, 1090)); 4 | -------------------------------------------------------------------------------- /0x00-ES6_basic/tests/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 | -------------------------------------------------------------------------------- /0x01-ES6_promise/0-promise.js: -------------------------------------------------------------------------------- 1 | export default function getResponseFromAPI() { 2 | const success = true; 3 | return new Promise((resolve, reject) => { 4 | if (success) { 5 | resolve(); 6 | } else { 7 | reject(); 8 | } 9 | }); 10 | } 11 | -------------------------------------------------------------------------------- /0x01-ES6_promise/1-promise.js: -------------------------------------------------------------------------------- 1 | export default function (boolean) { 2 | return new Promise((resolve, reject) => { 3 | const object = { 4 | status: 200, 5 | body: 'Success', 6 | }; 7 | 8 | if (boolean === true) { 9 | resolve(object); 10 | } else { 11 | reject(Error('The fake API is not working currently')); 12 | } 13 | }); 14 | } 15 | -------------------------------------------------------------------------------- /0x01-ES6_promise/100-await.js: -------------------------------------------------------------------------------- 1 | import { uploadPhoto, createUser } from './utils'; 2 | 3 | const asyncUploadUser = async () => { 4 | try { 5 | const photo = await uploadPhoto(); 6 | const user = await createUser(); 7 | 8 | return { photo, user }; 9 | } catch (error) { 10 | return { photo: null, user: null }; 11 | } 12 | }; 13 | 14 | export default asyncUploadUser; 15 | -------------------------------------------------------------------------------- /0x01-ES6_promise/2-then.js: -------------------------------------------------------------------------------- 1 | export default function handleResponseFromAPI(promise) { 2 | return promise 3 | .then(() => ({ status: 200, body: 'success' })) 4 | .catch(() => new Error()) 5 | .finally(() => console.log('Got a response from the API')); 6 | } 7 | -------------------------------------------------------------------------------- /0x01-ES6_promise/3-all.js: -------------------------------------------------------------------------------- 1 | import { uploadPhoto, createUser } from './utils'; 2 | 3 | export default function handleProfileSignup() { 4 | return Promise.all([uploadPhoto(), createUser()]) 5 | .then((value) => { 6 | console.log(`${value[0].body} ${value[1].firstName} ${value[1].lastName}`); 7 | }) 8 | 9 | .catch(() => console.log('Signup system offline')); 10 | } 11 | -------------------------------------------------------------------------------- /0x01-ES6_promise/4-user-promise.js: -------------------------------------------------------------------------------- 1 | export default function signUpUser(firstName, lastName) { 2 | return Promise.resolve({ 3 | firstName: `${firstName}`, 4 | lastName: `${lastName}`, 5 | }); 6 | } 7 | -------------------------------------------------------------------------------- /0x01-ES6_promise/5-photo-reject.js: -------------------------------------------------------------------------------- 1 | export default function uploadPhoto(filename) { 2 | return Promise.reject(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 | return Promise.allSettled([ 6 | signUpUser(firstName, lastName), 7 | uploadPhoto(fileName), 8 | ]).then((values) => { 9 | const arr = []; 10 | for (const item of values) { 11 | arr.push({ status: item.status, value: item.value || item.reason }); 12 | } 13 | return arr; 14 | }); 15 | } 16 | -------------------------------------------------------------------------------- /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/8-try.js: -------------------------------------------------------------------------------- 1 | export default function divideFunction(numerator, denominator) { 2 | if (denominator === 0) { 3 | throw new Error('cannot divide by 0'); 4 | } else { 5 | return numerator / denominator; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /0x01-ES6_promise/9-try.js: -------------------------------------------------------------------------------- 1 | export default function guardrail(mathFunction) { 2 | const queue = []; 3 | 4 | try { 5 | queue.push(mathFunction()); 6 | } catch (err) { 7 | queue.push(err.toString()); 8 | } finally { 9 | queue.push('Guardrail was processed'); 10 | } 11 | return queue; 12 | } 13 | -------------------------------------------------------------------------------- /0x01-ES6_promise/README.md: -------------------------------------------------------------------------------- 1 | ## 0x01. ES6 Promises 2 | -------------------------------------------------------------------------------- /0x01-ES6_promise/tests/0-main.js: -------------------------------------------------------------------------------- 1 | import getResponseFromAPI from "./0-promise.js"; 2 | 3 | const response = getResponseFromAPI(); 4 | console.log(response instanceof Promise); 5 | -------------------------------------------------------------------------------- /0x01-ES6_promise/tests/1-main.js: -------------------------------------------------------------------------------- 1 | import getFullResponseFromAPI from './1-promise'; 2 | 3 | console.log(getFullResponseFromAPI(true)); 4 | console.log(getFullResponseFromAPI(false)); 5 | -------------------------------------------------------------------------------- /0x01-ES6_promise/tests/100-main.js: -------------------------------------------------------------------------------- 1 | import asyncUploadUser 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/tests/2-main.js: -------------------------------------------------------------------------------- 1 | import handleResponseFromAPI from "./2-then"; 2 | 3 | const promise = Promise.resolve(); 4 | handleResponseFromAPI(promise); 5 | -------------------------------------------------------------------------------- /0x01-ES6_promise/tests/3-main.js: -------------------------------------------------------------------------------- 1 | import handleProfileSignup from "./3-all"; 2 | 3 | handleProfileSignup(); 4 | -------------------------------------------------------------------------------- /0x01-ES6_promise/tests/4-main.js: -------------------------------------------------------------------------------- 1 | import signUpUser from "./4-user-promise"; 2 | 3 | console.log(signUpUser("Bob", "Dylan")); 4 | -------------------------------------------------------------------------------- /0x01-ES6_promise/tests/5-main.js: -------------------------------------------------------------------------------- 1 | import uploadPhoto from './5-photo-reject'; 2 | 3 | console.log(uploadPhoto('guillaume.jpg')); 4 | -------------------------------------------------------------------------------- /0x01-ES6_promise/tests/6-main.js: -------------------------------------------------------------------------------- 1 | import handleProfileSignup from './6-final-user'; 2 | 3 | console.log(handleProfileSignup("Bob", "Dylan", "bob_dylan.jpg")); 4 | -------------------------------------------------------------------------------- /0x01-ES6_promise/tests/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/tests/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/tests/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 | -------------------------------------------------------------------------------- /0x02-ES6_classes/0-classroom.js: -------------------------------------------------------------------------------- 1 | export default class ClassRoom { 2 | constructor(maxStudentsSize) { 3 | this._maxStudentsSize = maxStudentsSize; 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /0x02-ES6_classes/1-make_classrooms.js: -------------------------------------------------------------------------------- 1 | import ClassRoom from './0-classroom'; 2 | 3 | export default function initializeRooms() { 4 | return [ 5 | new ClassRoom(19), 6 | new ClassRoom(20), 7 | new ClassRoom(34), 8 | ]; 9 | } 10 | -------------------------------------------------------------------------------- /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 ModelCar = this.constructor[Symbol.species]; 14 | return new ModelCar(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /0x02-ES6_classes/100-evcar.js: -------------------------------------------------------------------------------- 1 | import Car from './10-car'; 2 | 3 | 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 | 14 | export default EVCar; 15 | -------------------------------------------------------------------------------- /0x02-ES6_classes/2-hbtn_course.js: -------------------------------------------------------------------------------- 1 | export default class HolbertonCourse { 2 | constructor(name, length, students) { 3 | if (typeof name !== 'string') { 4 | throw new TypeError('Name must be a string'); 5 | } else if (typeof length !== 'number') { 6 | throw new TypeError('Length must be a number'); 7 | } else if (!Array.isArray(students)) { 8 | throw new TypeError('Students must be an array of strings'); 9 | } 10 | 11 | this._name = name; 12 | this._length = length; 13 | this._students = students; 14 | } 15 | 16 | get name() { 17 | return this._name; 18 | } 19 | 20 | get length() { 21 | return this._length; 22 | } 23 | 24 | get students() { 25 | return this._students; 26 | } 27 | 28 | set name(name) { 29 | if (typeof name !== 'string') { 30 | throw new TypeError('Name must be a string'); 31 | } 32 | this._name = name; 33 | } 34 | 35 | set length(length) { 36 | if (typeof length !== 'number') { 37 | throw new TypeError('Length must be a number'); 38 | } 39 | this._length = length; 40 | } 41 | 42 | set students(students) { 43 | if (!Array.isArray(students)) { 44 | throw new TypeError('Students must be an array of strings'); 45 | } 46 | this._students = students; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /0x02-ES6_classes/3-currency.js: -------------------------------------------------------------------------------- 1 | export default class Currency { 2 | constructor(code, name) { 3 | if (typeof code !== 'string') { 4 | throw new TypeError('Code must be a string'); 5 | } else if (typeof name !== 'string') { 6 | throw new TypeError('Name must be a string'); 7 | } 8 | 9 | this._code = code; 10 | this._name = name; 11 | } 12 | 13 | get name() { 14 | return this._name; 15 | } 16 | 17 | get code() { 18 | return this._code; 19 | } 20 | 21 | set name(name) { 22 | if (typeof name !== 'string') { 23 | throw new TypeError('Name must be a string'); 24 | } 25 | this._name = name; 26 | } 27 | 28 | set code(code) { 29 | if (typeof code !== 'string') { 30 | throw new TypeError('Code must be a string'); 31 | } 32 | this._code = code; 33 | } 34 | 35 | displayFullCurrency() { 36 | return `${this._name} (${this._code})`; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /0x02-ES6_classes/4-pricing.js: -------------------------------------------------------------------------------- 1 | import Currency from './3-currency'; 2 | 3 | export default class Pricing { 4 | constructor(amount, currency) { 5 | if (typeof amount !== 'number') { 6 | throw new TypeError('Amount must be a number'); 7 | } else if (!(currency instanceof Currency)) { 8 | throw new TypeError('Currency must be an instance of class Currency'); 9 | } 10 | 11 | this._amount = amount; 12 | this._currency = currency; 13 | } 14 | 15 | get amount() { 16 | return this._amount; 17 | } 18 | 19 | get currency() { 20 | return this._currency; 21 | } 22 | 23 | set amount(amount) { 24 | if (typeof amount !== 'number') { 25 | throw new TypeError('Amount must be a number'); 26 | } 27 | this._amount = amount; 28 | } 29 | 30 | set currency(currency) { 31 | if (!(currency instanceof Currency)) { 32 | throw new TypeError('Currency must be an instance of class Currency'); 33 | } 34 | this._currency = currency; 35 | } 36 | 37 | displayFullPrice() { 38 | return `${this._amount} ${this._currency.name} (${this._currency.code})`; 39 | } 40 | 41 | static convertPrice(amount, conversionRate) { 42 | if (typeof amount !== 'number') { 43 | throw new TypeError('Amount must be a number'); 44 | } else if (typeof conversionRate !== 'number') { 45 | throw new TypeError('Conversion rate must be a number'); 46 | } 47 | 48 | return amount * conversionRate; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /0x02-ES6_classes/5-building.js: -------------------------------------------------------------------------------- 1 | export default class Building { 2 | constructor(sqft = 0) { 3 | if (this.constructor !== Building 4 | && typeof this.evacuationWarningMessage !== 'function') { 5 | throw new Error('Class extending Building must override evacuationWarningMessage'); 6 | } 7 | 8 | this._sqft = sqft; 9 | } 10 | 11 | get sqft() { 12 | return this._sqft; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /0x02-ES6_classes/6-sky_high.js: -------------------------------------------------------------------------------- 1 | import Building from './5-building'; 2 | 3 | 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 | evacuationWarningMessage() { 14 | return (`Evacuate slowly the ${this.floors} floors`); 15 | } 16 | } 17 | 18 | export default SkyHighBuilding; 19 | -------------------------------------------------------------------------------- /0x02-ES6_classes/7-airport.js: -------------------------------------------------------------------------------- 1 | export default class Airport { 2 | constructor(name, code) { 3 | if (typeof name !== 'string') { 4 | throw new TypeError('Name must be a string'); 5 | } else if (typeof code !== 'string') { 6 | throw new TypeError('Code must be a string'); 7 | } 8 | 9 | this._name = name; 10 | this._code = code; 11 | } 12 | 13 | get [Symbol.toStringTag]() { 14 | return `${this._code}`; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /0x02-ES6_classes/8-hbtn_class.js: -------------------------------------------------------------------------------- 1 | export default class HolbertonClass { 2 | constructor(size, location) { 3 | if (typeof size !== 'number') { 4 | throw new TypeError('Size must be a number'); 5 | } else if (typeof location !== 'string') { 6 | throw new TypeError('Location must be a string'); 7 | } 8 | 9 | this._size = size; 10 | this._location = location; 11 | } 12 | 13 | [Symbol.toPrimitive](hint) { 14 | if (hint === 'number') { 15 | return this._size; 16 | } 17 | return this._location; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /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 | const class2019 = new HolbertonClass(2019, 'San Francisco'); 16 | const class2020 = new HolbertonClass(2020, 'San Francisco'); 17 | 18 | export class StudentHolberton { 19 | constructor(firstName, lastName, holbertonClass) { 20 | this._firstName = firstName; 21 | this._lastName = lastName; 22 | this._holbertonClass = holbertonClass; 23 | } 24 | 25 | get fullName() { 26 | return `${this._firstName} ${this._lastName}`; 27 | } 28 | 29 | get holbertonClass() { 30 | return this._holbertonClass; 31 | } 32 | 33 | get fullStudentDescription() { 34 | return `${this._firstName} ${this._lastName} - ${this._holbertonClass.year} - ${this._holbertonClass.location}`; 35 | } 36 | } 37 | const student1 = new StudentHolberton('Guillaume', 'Salva', class2020); 38 | const student2 = new StudentHolberton('John', 'Doe', class2020); 39 | const student3 = new StudentHolberton('Albert', 'Clinton', class2019); 40 | const student4 = new StudentHolberton('Donald', 'Bush', class2019); 41 | const student5 = new StudentHolberton('Jason', 'Sandler', class2019); 42 | 43 | const listOfStudents = [student1, student2, student3, student4, student5]; 44 | 45 | export default listOfStudents; 46 | -------------------------------------------------------------------------------- /0x02-ES6_classes/README.md: -------------------------------------------------------------------------------- 1 | ## 0x02. ES6 classes 2 | -------------------------------------------------------------------------------- /0x02-ES6_classes/tests/0-main.js: -------------------------------------------------------------------------------- 1 | import ClassRoom from "./0-classroom.js"; 2 | 3 | const room = new ClassRoom(10); 4 | console.log(room._maxStudentsSize) 5 | -------------------------------------------------------------------------------- /0x02-ES6_classes/tests/1-main.js: -------------------------------------------------------------------------------- 1 | import initializeRooms from './1-make_classrooms.js'; 2 | 3 | console.log(initializeRooms()); 4 | -------------------------------------------------------------------------------- /0x02-ES6_classes/tests/10-main.js: -------------------------------------------------------------------------------- 1 | import Car from "./10-car.js"; 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/tests/100-main.js: -------------------------------------------------------------------------------- 1 | import EVCar from './100-evcar.js'; 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 | -------------------------------------------------------------------------------- /0x02-ES6_classes/tests/2-main.js: -------------------------------------------------------------------------------- 1 | import HolbertonCourse from "./2-hbtn_course.js"; 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 | } 11 | catch(err) { 12 | console.log(err); 13 | } 14 | 15 | try { 16 | const c2 = new HolbertonCourse("ES6", "1", ["Bob", "Jane"]); 17 | } 18 | catch(err) { 19 | console.log(err); 20 | } 21 | -------------------------------------------------------------------------------- /0x02-ES6_classes/tests/3-main.js: -------------------------------------------------------------------------------- 1 | import Currency from "./3-currency.js"; 2 | 3 | const dollar = new Currency('$', 'Dollars'); 4 | console.log(dollar.displayFullCurrency()); 5 | -------------------------------------------------------------------------------- /0x02-ES6_classes/tests/4-main.js: -------------------------------------------------------------------------------- 1 | import Pricing from './4-pricing.js'; 2 | import Currency from './3-currency.js'; 3 | 4 | const p = new Pricing(100, new Currency("EUR", "Euro")) 5 | console.log(p); 6 | console.log(p.displayFullPrice()); 7 | -------------------------------------------------------------------------------- /0x02-ES6_classes/tests/5-main.js: -------------------------------------------------------------------------------- 1 | import Building from './5-building.js'; 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 | -------------------------------------------------------------------------------- /0x02-ES6_classes/tests/6-main.js: -------------------------------------------------------------------------------- 1 | import SkyHighBuilding from './6-sky_high.js'; 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/tests/7-main.js: -------------------------------------------------------------------------------- 1 | import Airport from "./7-airport.js"; 2 | 3 | const airportSF = new Airport('San Francisco Airport', 'SFO'); 4 | console.log(airportSF); 5 | console.log(airportSF.toString()); 6 | -------------------------------------------------------------------------------- /0x02-ES6_classes/tests/8-main.js: -------------------------------------------------------------------------------- 1 | import HolbertonClass from "./8-hbtn_class.js"; 2 | 3 | const hc = new HolbertonClass(12, "Mezzanine") 4 | console.log(Number(hc)); 5 | console.log(String(hc)); 6 | -------------------------------------------------------------------------------- /0x02-ES6_classes/tests/9-main.js: -------------------------------------------------------------------------------- 1 | import listOfStudents from "./9-hoisting.js"; 2 | 3 | console.log(listOfStudents); 4 | 5 | const listPrinted = listOfStudents.map( 6 | student => student.fullStudentDescription 7 | ); 8 | 9 | console.log(listPrinted) 10 | -------------------------------------------------------------------------------- /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/1-get_list_student_ids.js: -------------------------------------------------------------------------------- 1 | export default function getListStudentIds(list) { 2 | if (Array.isArray(list)) { 3 | return list.map((obj) => obj.id); 4 | } 5 | return []; 6 | } 7 | -------------------------------------------------------------------------------- /0x03-ES6_data_manipulation/10-update_uniq_items.js: -------------------------------------------------------------------------------- 1 | export default function updateUniqueItems(map) { 2 | const list = map; 3 | 4 | if (list instanceof Map) { 5 | for (const [key, value] of list) { 6 | if (value === 1) { 7 | list.set(key, 100); 8 | } 9 | } 10 | } else { 11 | throw new Error('Cannot process'); 12 | } 13 | return list; 14 | } 15 | -------------------------------------------------------------------------------- /0x03-ES6_data_manipulation/100-weak.js: -------------------------------------------------------------------------------- 1 | export const weakMap = new WeakMap(); 2 | export function queryAPI(endpoint) { 3 | let count = weakMap.get(endpoint) || 0; 4 | count += 1; 5 | 6 | if (count >= 5) { 7 | throw new Error('Endpoint load is high'); 8 | } else { 9 | weakMap.set(endpoint, count); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /0x03-ES6_data_manipulation/2-get_students_by_loc.js: -------------------------------------------------------------------------------- 1 | export default function getStudentsByLocation(students, city) { 2 | return students.filter((obj) => obj.location === city); 3 | } 4 | -------------------------------------------------------------------------------- /0x03-ES6_data_manipulation/3-get_ids_sum.js: -------------------------------------------------------------------------------- 1 | export default function getStudentIdsSum(students) { 2 | return students.reduce((acc, c) => acc + c.id, 0); 3 | } 4 | -------------------------------------------------------------------------------- /0x03-ES6_data_manipulation/4-update_grade_by_city.js: -------------------------------------------------------------------------------- 1 | export default function updateStudentGradeByCity(listStudents, city, newGrades) { 2 | const students = listStudents.filter((student) => student.location === city); 3 | for (const student of students) { 4 | student.grade = 'N/A'; 5 | } 6 | const newStudents = students.map((student) => { 7 | const single = student; 8 | for (const grade of newGrades) { 9 | if (single.id === grade.studentId) { 10 | single.grade = grade.grade; 11 | } 12 | } 13 | return single; 14 | }); 15 | return newStudents; 16 | } 17 | -------------------------------------------------------------------------------- /0x03-ES6_data_manipulation/5-typed_arrays.js: -------------------------------------------------------------------------------- 1 | export default function createInt8TypedArray(length, position, value) { 2 | const arr = new ArrayBuffer(length); 3 | const val = new DataView(arr); 4 | 5 | try { 6 | val.setInt8(position, value); 7 | } catch (e) { 8 | throw Error('Position outside range'); 9 | } 10 | return val; 11 | } 12 | -------------------------------------------------------------------------------- /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(set, array) { 2 | return array.every((value) => set.has(value)); 3 | } 4 | -------------------------------------------------------------------------------- /0x03-ES6_data_manipulation/8-clean_set.js: -------------------------------------------------------------------------------- 1 | export default function cleanSet(set, startString) { 2 | const list = []; 3 | 4 | if ( 5 | typeof set !== 'object' 6 | || typeof startString !== 'string' 7 | || startString.length === 0 8 | ) { 9 | return ''; 10 | } 11 | 12 | for (const item of set) { 13 | if (item && item.startsWith(startString)) { 14 | list.push(item.slice(startString.length)); 15 | } 16 | } 17 | 18 | return list.join('-'); 19 | } 20 | -------------------------------------------------------------------------------- /0x03-ES6_data_manipulation/9-groceries_list.js: -------------------------------------------------------------------------------- 1 | export default function groceriesList() { 2 | const items = new Map(); 3 | items.set('Apples', 10); 4 | items.set('Tomatoes', 10); 5 | items.set('Pasta', 1); 6 | items.set('Rice', 1); 7 | items.set('Banana', 5); 8 | 9 | return items; 10 | } 11 | -------------------------------------------------------------------------------- /0x03-ES6_data_manipulation/README.md: -------------------------------------------------------------------------------- 1 | ## 0x03. ES6 data manipulation 2 | -------------------------------------------------------------------------------- /0x03-ES6_data_manipulation/tests/0-main.js: -------------------------------------------------------------------------------- 1 | import getListStudents from "./0-get_list_students.js"; 2 | 3 | console.log(getListStudents()); 4 | -------------------------------------------------------------------------------- /0x03-ES6_data_manipulation/tests/1-main.js: -------------------------------------------------------------------------------- 1 | import getListStudentIds from "./1-get_list_student_ids.js"; 2 | import getListStudents from "./0-get_list_students.js"; 3 | 4 | console.log(getListStudentIds("hello")); 5 | console.log(getListStudentIds(getListStudents())); 6 | -------------------------------------------------------------------------------- /0x03-ES6_data_manipulation/tests/10-main.js: -------------------------------------------------------------------------------- 1 | import updateUniqueItems from "./10-update_uniq_items.js"; 2 | import groceriesList from "./9-groceries_list.js"; 3 | 4 | const map = groceriesList(); 5 | console.log(map); 6 | 7 | updateUniqueItems(map) 8 | console.log(map); 9 | -------------------------------------------------------------------------------- /0x03-ES6_data_manipulation/tests/100-main.js: -------------------------------------------------------------------------------- 1 | import { queryAPI, weakMap } from "./100-weak.js"; 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/tests/2-main.js: -------------------------------------------------------------------------------- 1 | import getListStudents from "./0-get_list_students.js"; 2 | import getStudentsByLocation from "./2-get_students_by_loc.js"; 3 | 4 | const students = getListStudents(); 5 | 6 | console.log(getStudentsByLocation(students, 'San Francisco')); 7 | -------------------------------------------------------------------------------- /0x03-ES6_data_manipulation/tests/3-main.js: -------------------------------------------------------------------------------- 1 | import getListStudents from "./0-get_list_students.js"; 2 | import getStudentIdsSum from "./3-get_ids_sum.js"; 3 | 4 | const students = getListStudents(); 5 | const value = getStudentIdsSum(students); 6 | 7 | console.log(value); 8 | -------------------------------------------------------------------------------- /0x03-ES6_data_manipulation/tests/4-main.js: -------------------------------------------------------------------------------- 1 | import getListStudents from "./0-get_list_students.js"; 2 | import updateStudentGradeByCity from "./4-update_grade_by_city.js"; 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/tests/5-main.js: -------------------------------------------------------------------------------- 1 | import createInt8TypedArray from "./5-typed_arrays.js"; 2 | 3 | console.log(createInt8TypedArray(10, 2, 89)); 4 | -------------------------------------------------------------------------------- /0x03-ES6_data_manipulation/tests/6-main.js: -------------------------------------------------------------------------------- 1 | import setFromArray from "./6-set.js"; 2 | 3 | console.log(setFromArray([12, 32, 15, 78, 98, 15])); 4 | -------------------------------------------------------------------------------- /0x03-ES6_data_manipulation/tests/7-main.js: -------------------------------------------------------------------------------- 1 | import hasValuesFromArray from "./7-has_array_values.js"; 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/tests/8-main.js: -------------------------------------------------------------------------------- 1 | import cleanSet from "./8-clean_set.js"; 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/tests/9-main.js: -------------------------------------------------------------------------------- 1 | import groceriesList from "./9-groceries_list.js"; 2 | 3 | console.log(groceriesList()); 4 | -------------------------------------------------------------------------------- /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/js/main.js: -------------------------------------------------------------------------------- 1 | var student1 = { 2 | firstName: "Zeliq", 3 | lastName: "Shannon", 4 | age: 40, 5 | location: "Nakuru" 6 | }; 7 | var student2 = { 8 | firstName: "John", 9 | lastName: "Doe", 10 | age: 37, 11 | location: "Nairobi" 12 | }; 13 | var studentsList = [student1, student2]; 14 | var table = document.createElement('table'); 15 | var tbody = document.createElement('tbody'); 16 | table.style.background = "pink"; 17 | table.appendChild(tbody); 18 | studentsList.forEach(function (student) { 19 | var row = document.createElement('tr'); 20 | var nameCell = document.createElement('td'); 21 | var locationCell = document.createElement('td'); 22 | nameCell.textContent = student.firstName; 23 | locationCell.textContent = student.location; 24 | nameCell.style.border = "1px solid pink"; 25 | locationCell.style.border = "1px solid pink"; 26 | nameCell.style.padding = "5px"; 27 | locationCell.style.padding = "5px"; 28 | row.appendChild(nameCell); 29 | row.appendChild(locationCell); 30 | tbody.appendChild(row); 31 | }); 32 | document.body.appendChild(table); 33 | -------------------------------------------------------------------------------- /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: "Zeliq", 10 | lastName: "Shannon", 11 | age: 40, 12 | location: "Nakuru" 13 | }; 14 | 15 | const student2: Student = { 16 | firstName: "John", 17 | lastName: "Doe", 18 | age: 37, 19 | location: "Nairobi" 20 | }; 21 | 22 | const studentsList: Student[] = [student1, student2]; 23 | 24 | const table = document.createElement('table'); 25 | const tbody = document.createElement('tbody'); 26 | 27 | table.style.background = "pink"; 28 | table.appendChild(tbody); 29 | 30 | studentsList.forEach((student: Student): void => { 31 | const row = document.createElement('tr'); 32 | const nameCell = document.createElement('td'); 33 | const locationCell = document.createElement('td'); 34 | 35 | nameCell.textContent = student.firstName; 36 | locationCell.textContent = student.location; 37 | 38 | nameCell.style.border = "1px solid pink"; 39 | locationCell.style.border = "1px solid pink"; 40 | nameCell.style.padding = "5px"; 41 | locationCell.style.padding = "5px"; 42 | 43 | row.appendChild(nameCell); 44 | row.appendChild(locationCell); 45 | tbody.appendChild(row); 46 | }); 47 | 48 | document.body.appendChild(table); 49 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/js/main.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | exports.__esModule = true; 3 | exports.printTeacher = void 0; 4 | var printTeacher = function (firstName, lastName) { 5 | return firstName[0] + ". " + lastName; 6 | }; 7 | exports.printTeacher = printTeacher; 8 | -------------------------------------------------------------------------------- /0x04-TypeScript/task_1/js/main.ts: -------------------------------------------------------------------------------- 1 | interface Teacher { 2 | readonly firstName: string; 3 | readonly lastName: string; 4 | fullTimeEmployee: boolean; 5 | yearsOfExperience?: number; 6 | location: string; 7 | contract: boolean; 8 | [propName: string]: any; 9 | } 10 | 11 | interface Directors extends Teacher { 12 | numberOfReports: number; 13 | } 14 | 15 | interface printTeacherFunction { 16 | (firstName: string, lastName: string): string; 17 | } 18 | 19 | const printTeacher: printTeacherFunction = (firstName, lastName) => { 20 | return `${firstName[0]}. ${lastName}`; 21 | }; 22 | 23 | interface StudentConstructor { 24 | new (firstName: string, lastName: string): StudentClassInterface; 25 | } 26 | 27 | interface StudentClassInterface { 28 | workOnHomework(): string; 29 | displayName(): string; 30 | } 31 | 32 | const StudentClass: StudentConstructor = class StudentClass implements StudentClassInterface { 33 | firstName: string; 34 | lastName: string; 35 | 36 | constructor(firstName: string, lastName: string) { 37 | this.firstName = firstName; 38 | this.lastName = lastName; 39 | } 40 | workOnHomework(): string { 41 | return "Currently working"; 42 | } 43 | displayName(): string { 44 | return this.firstName; 45 | } 46 | }; 47 | 48 | export { printTeacher, StudentClass }; 49 | -------------------------------------------------------------------------------- /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.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_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): Director | Teacher { 42 | if (typeof salary === "number" && salary < 500) { 43 | return new Teacher(); 44 | } else { 45 | return new Director(); 46 | } 47 | } 48 | 49 | console.log(createEmployee(200)); 50 | console.log(createEmployee(1000)); 51 | console.log(createEmployee("$500")); 52 | 53 | // functions specific to employees 54 | 55 | function isDirector(employee: Teacher | Director): boolean { 56 | return employee instanceof Director; 57 | } 58 | 59 | function executeWork(employee: Teacher | Director): string { 60 | if (employee instanceof Director) { 61 | return employee.workDirectorTasks(); 62 | } else if (employee instanceof Teacher) { 63 | return employee.workTeacherTasks(); 64 | } 65 | } 66 | 67 | console.log(executeWork(createEmployee(200))); 68 | console.log(executeWork(createEmployee(1000))); 69 | 70 | // String literal types 71 | 72 | type Subjects = "Math" | "History"; 73 | 74 | function teachClass(todayClass: Subjects): string { 75 | if (todayClass === "Math") { 76 | return `Teaching Math`; 77 | } else if (todayClass === "History") { 78 | return `Teaching History`; 79 | } 80 | } 81 | 82 | console.log(teachClass("Math")); 83 | console.log(teachClass("History")); 84 | -------------------------------------------------------------------------------- /0x04-TypeScript/task_2/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_2/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_2/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_3/js/crud.d.ts: -------------------------------------------------------------------------------- 1 | import { RowID, RowElement } from "./interface"; 2 | 3 | export declare function insertRow(row: RowElement): RowID; 4 | export declare function deleteRow(rowId: RowID): void; 5 | export declare function updateRow(rowId: RowID, row: RowElement): RowID; 6 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /0x04-TypeScript/task_3/js/main.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | import { RowID, RowElement } from "./interface"; 4 | import * as CRUD from "./crud"; 5 | 6 | const row: RowElement = { 7 | firstName: "Guillaume", 8 | lastName: "Salva", 9 | }; 10 | 11 | const newRowID: RowID = CRUD.insertRow(row); 12 | const UpdatedRow: RowElement = { age: 23, ...row }; 13 | 14 | CRUD.updateRow(newRowID, UpdatedRow); 15 | CRUD.deleteRow(newRowID); 16 | -------------------------------------------------------------------------------- /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.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.46.0", 29 | "webpack-cli": "^3.3.9", 30 | "webpack-dev-server": "^3.8.2" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /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/js/main.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | /// 4 | /// 5 | /// 6 | 7 | export const cpp = new Subjects.Cpp(); 8 | export const java = new Subjects.Java(); 9 | export const react = new Subjects.React(); 10 | export const cTeacher: Subjects.Teacher = { 11 | firstName: "Bobby", 12 | lastName: "Wine", 13 | experienceTeachingC: 10, 14 | }; 15 | 16 | console.log("C++"); 17 | cpp.setTeacher = cTeacher; 18 | console.log(cpp.getRequirements()); 19 | console.log(cpp.getAvailableTeacher()); 20 | 21 | console.log("Java"); 22 | java.setTeacher = cTeacher; 23 | console.log(java.getRequirements()); 24 | console.log(java.getAvailableTeacher()); 25 | 26 | console.log("React"); 27 | react.setTeacher = cTeacher; 28 | console.log(react.getRequirements()); 29 | console.log(react.getAvailableTeacher()); 30 | -------------------------------------------------------------------------------- /0x04-TypeScript/task_4/js/subjects/Cpp.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | namespace Subjects { 4 | export interface Teacher { 5 | experienceTeachingC?: number; 6 | } 7 | 8 | export class Cpp extends Subject { 9 | getRequirements(): string { 10 | return "Here is the list of requirements for Cpp"; 11 | } 12 | getAvailableTeacher(): string { 13 | const xp = this.teacher.experienceTeachingC; 14 | if (xp > 0) { 15 | return `Available Teacher: ${this.teacher.firstName}`; 16 | } else { 17 | return "No available teacher"; 18 | } 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /0x04-TypeScript/task_4/js/subjects/Java.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | namespace Subjects { 4 | export interface Teacher { 5 | experienceTeachingJava?: number; 6 | } 7 | 8 | export class Java extends Subject { 9 | getRequirements(): string { 10 | return "Here is the list of requirements for Java"; 11 | } 12 | 13 | getAvailableTeacher(): string { 14 | const xp = this.teacher.experienceTeachingJava; 15 | return xp > 0 ? `Available Teacher: ${this.teacher.firstName}` : "No available teacher"; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /0x04-TypeScript/task_4/js/subjects/React.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | namespace Subjects { 4 | export interface Teacher { 5 | experienceTeachingReact?: number; 6 | } 7 | 8 | export class React extends Subject { 9 | getRequirements(): string { 10 | return "Here is the list of requirements for React"; 11 | } 12 | 13 | getAvailableTeacher(): string { 14 | const xp = this.teacher.experienceTeachingReact; 15 | return xp > 0 ? `Available Teacher: ${this.teacher.firstName}` : "No available teacher"; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /0x04-TypeScript/task_4/js/subjects/Subject.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | namespace Subjects { 4 | export class Subject { 5 | teacher: Subjects.Teacher; 6 | 7 | set setTeacher(teacher: Teacher) { 8 | this.teacher = teacher; 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /0x04-TypeScript/task_4/js/subjects/Teacher.ts: -------------------------------------------------------------------------------- 1 | namespace Subjects { 2 | export interface Teacher { 3 | firstName: string; 4 | lastName: string; 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /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: "major"; 4 | } 5 | 6 | interface MinorCredits { 7 | credits: number; 8 | brand: "minor"; 9 | } 10 | 11 | function sumMajorCredits(subject1: MajorCredits, subject2: MajorCredits) { 12 | return subject1.credits + subject2.credits; 13 | } 14 | 15 | function sumMinorCredits(subject1: MinorCredits, subject2: MinorCredits) { 16 | return subject1.credits + subject2.credits; 17 | } 18 | -------------------------------------------------------------------------------- /0x04-TypeScript/task_5/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_5/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/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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # alx-frontend-javascript 2 | --------------------------------------------------------------------------------