This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Определите зависимость «один ко многим» между объектами, чтобы при изменении состояния одного объекта все его иждивенцы уведомлялись и обновлялись автоматически. | |
| // Используется когда изменение одного объекта требует изменения другого. | |
| // class Product { | |
| // constructor() { | |
| // this.price = 0; | |
| // this.observers = []; | |
| // } | |
| // subscribe(observer) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const add = a => { | |
| let sum = a; | |
| const deepAdd = b => { | |
| sum = sum + b; | |
| return deepAdd; | |
| } | |
| deepAdd.valueOf = () => sum; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const add = a => { | |
| let sum = a; | |
| const deepAdd = b => { | |
| sum = sum + b; | |
| return deepAdd; | |
| } | |
| deepAdd.valueOf = () => sum; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const sum = x => { | |
| let result = x; | |
| const innerSum = y => { | |
| result = x + y; | |
| return innerSum; | |
| }; | |
| innerSum.valueOf = () => result; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const array = ['1', -9, null, -4, '3', 7, 8, NaN, undefined, 3, '-5', 2]; | |
| const getSumOfNaturalNumbers = (array) => { | |
| const filteredArray = array.filter(item => !!item); | |
| const mappedArray = filteredArray.map(Math.abs); | |
| const minValue = Math.min(...mappedArray); | |
| const maxValue = Math.max(...mappedArray); | |
| const arrayWithoutMinAndMax = mappedArray.filter(item => item !== minValue && item !== maxValue); | |
| return arrayWithoutMinAndMax.reduce((item, acc) => item + acc, 0); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // https://cs.stanford.edu/people/miles/iso8859.html | |
| const alphabetized = (str) => { | |
| const chars = str.split(''); | |
| const filteredChars = chars.filter(item => item.charCodeAt(item.indexOf(item)) <= 255); | |
| const sortedChars = filteredChars.sort((a, b) => a.localeCompare(b, 'en-US-u-kf-upper')); | |
| return sortedChars.join('').trim(); | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const flat = (arr, deep = 1) => { | |
| let newArr = []; | |
| for (let i = 0; i < arr.length; i++) { | |
| const current = arr[i]; | |
| const canDeep = Array.isArray(current) && deep !== 0; | |
| const element = canDeep ? flat(current, deep - 1) : [current]; | |
| // оптимизировать через guard expression | |
| newArr = current !== '' ? [...newArr, ...element] : newArr; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let where = document.createElement('div'); | |
| let class1 = `class-1`; | |
| let class2 = `class-1-3`; | |
| let text1 = '123'; | |
| let text2 = 'abc!@#213'; | |
| let stat = { | |
| tags: { P: 1, B: 2 }, | |
| classes: { [class1]: 2, [class2]: 1 }, | |
| texts: 3 | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const fizzbuzz = (begin, end) => { | |
| for (let i = begin; i <= end; i++) { | |
| const hasFizz = i % 3 === 0; | |
| const hasBuzz = i % 5 === 0; | |
| const fizz = hasFizz ? 'Fizz' : ''; | |
| const buzz = hasBuzz ? 'Buzz' : ''; | |
| console.log(hasFizz || hasBuzz ? `${fizz}${buzz}` : i); | |
| } | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const person = { | |
| name: 'Владилен' | |
| } | |
| function info(phone, email) { | |
| console.log(`Имя: ${this.name}, Тел.:${phone}, Email: ${email}`) | |
| } | |
| // Demo | |
| // info.bind(person)('12345', 'v@mail.ru') |