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 decodedResponse = await fetch('https://www.anysite.rss.xml', { | |
| headers: { | |
| 'Content-Type': 'text/xml;charset=ISO-8859-1', | |
| }, | |
| }) | |
| .then(r => r.arrayBuffer()) // resolve the response stream for buffer | |
| .then(d => { | |
| const dataView = new DataView(d); // creates a DataView object representing the buffer data | |
| const isoDecoder = new TextDecoder('ISO-8859-1'); // creates an instance of the our decoder | |
| const decodedString = isoDecoder.decode(dataView); // so we pass the stream of bytes for the decoder do its job |
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
| /** | |
| * flatten. | |
| * | |
| * Дан массив, в котором могут храниться любые типы данных. | |
| * Нужно реализовать функцию, которая разворачивает вложенные массивы в исходный массив. | |
| * Данные остальных типов должны остаться без изменений. | |
| * Решение должно учитывать любую вложенность элементов (т.е. не должно содержать рекурсивные вызовы). | |
| * Встроенный метод Array.flat() использовать нельзя | |
| */ |
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 utils = { | |
| findMiddleIndex: (list) => Math.floor(list.length / 2) | |
| }; | |
| class NotFoundException { | |
| constructor(message) { | |
| this.name = "Не найдено"; | |
| this.message = message; | |
| } | |
| } |
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 MyIterator { | |
| // Конструктор в качестве аргументов принимает символы английского языка и длину перестановки | |
| constructor(str, len) { | |
| this.str = str; | |
| this.len = len; | |
| this.acc = []; | |
| this.prepare(); | |
| } |
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
| 0. This is data for String from Remote! |
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
| function threeSum(nums, target = 0) { | |
| if (nums.length < 3) return []; | |
| const result = {} | |
| nums.sort((a, b) => a - b).every((a, i) => { | |
| let j = i + 1 | |
| let k = nums.length - 1 | |
| while (j < k) { |
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
| fibonacci(9) // 34 | |
| // fibonacci(10) // '0, 1, 1, 2, 3, 5, 8, 13, 21, 34' | |
| function fibonacci(num) { | |
| const result = [0, 1] | |
| for (let i = 2; i <= num; i++) { | |
| result.push(result[i - 2] + result[i - 1]) | |
| } | |
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
| countVowels('Hello') // 2 | |
| function countVowels(str) { | |
| return str.replace(/[^eyuioa]/g, '').length | |
| } |
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
| anagram('finder2', 'Fr ie2n.d ,') // true | |
| const anagram = (a, b) => [...a.toLowerCase()].sort().join('') === [...b.toLowerCase()].sort().join('') | |
| // function anagram(firstStr, secondStr) { | |
| // const strToArr = str => [...str.replace(/[^\A-Za-zА-Яа-я0-9]/g, '').toLowerCase()] | |
| // const sortNat = str => str.sort((a, b) => new Intl.Collator(['en', 'ru'], { numeric: true }).compare(a, b)) | |
| // const sortedFirstStr = sortNat(strToArr(firstStr)).join('') | |
| // const sortedSecondStr = sortNat(strToArr(secondStr)).join('') |
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
| function fizzBuzz(num) { | |
| return Array.from(Array(num)).map((_, key) => { | |
| const num = key + 1 | |
| const fizzTest = num % 3 === 0 | |
| const buzzTest = num % 5 === 0 | |
| return fizzTest && buzzTest | |
| ? 'fizzbuzz' | |
| : buzzTest | |
| ? 'buzz' |
NewerOlder