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
| cycleLinkedList = (values) => ( | |
| values | |
| .map((value) => ({ | |
| value, | |
| })) | |
| .map((value, index, cLL) => { | |
| let prev, next; | |
| if(index === 0) { | |
| prev = cLL[cLL.length - 1] | |
| next = cLL[index + 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
| function directSearch(string, subString) { | |
| for(let i = 0; i + subString.length - 1 < string.length; i++) { | |
| let isSubstring = false | |
| for(let j = 0; j < subString.length; j++) { | |
| isSubstring = string[i+j] === subString[j] | |
| if (!isSubstring) break | |
| } | |
| if(isSubstring) return true | |
| } |
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 callPromisesSync(arrayOfProimiseFunc) { | |
| return arrayOfProimiseFunc.reduce((prevPromise, promise) => { | |
| return prevPromise.then(promise) | |
| }, Promise.resolve()) | |
| } | |
| // test | |
| const arrayOfProimiseFunc = [ | |
| () => new Promise((resolve, reject) => setTimeout(() => resolve(console.log('first')), 3000)), |
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
| // my variant | |
| function copyObjectDeep(object) { | |
| function copyArray(array) { | |
| return array.map((item) => { | |
| if ((item instanceof Object) && !(item instanceof Array)) { | |
| return createNewObject(item) | |
| } else if (item instanceof Array) { | |
| return copyArray(item) | |
| } | |
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 EventEmitter { | |
| handlers = [] | |
| on(eventName, handler) { | |
| this.handlers[eventName] = handler | |
| } | |
| emit(eventName, ...args) { | |
| console.log('s') | |
| this.handlers[eventName](...args) |
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 montyHall(reRandom) { | |
| const prize = Math.trunc(Math.random() * 3 + 1) | |
| const variants = Array.from({ length: 3 }, (v, k) => ({ index: k + 1, value: false })) | |
| const prizeVariant = variants.find(variant => variant.index === prize) | |
| prizeVariant.value = true | |
| const choice = Math.trunc(Math.random() * 3 + 1) | |
| const removedElem = variants.find(variant => variant.index !== choice && !variant.value) | |
| const newVariants = variants.filter(variant => removedElem.index !== variant.index) |
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 generateTypesFromObject = ({ fullTypeSchema, data }) => ( | |
| Object.keys(data).reduce((ac, key, index, { length }) => ( | |
| ac += index === length - 1 ? `$${key}: ${fullTypeSchema[key]}` : `$${key}: ${fullTypeSchema[key]}, ` | |
| ), '') | |
| ) | |
| const generateVariablesFroObject = ({ data }) => ( | |
| Object.keys(data).reduce((ac, key, index, { length }) => ( | |
| ac += index === length - 1 ? `${key}: $${key}}` : `${key}: $${key}}, ` | |
| ), '') |
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
| _getTotal = () => { | |
| if (this.props.filters) { | |
| return this.props.filters.reduce((a, b) => { | |
| if (b.count) a += b.count; | |
| return a; | |
| }, 0); | |
| } | |
| return 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
| # remove files with "@" symbol in name, also remove files in sub folders | |
| # date: 2019-01-03, author: https://github.com/lysenko-sergey-developer | |
| import os | |
| import re | |
| def remover(folder_path): | |
| target_files = os.listdir(path=folder_path) | |
| for file in target_files: | |
| result = re.findall(r'@', file) | |
| cur_path = folder_path + "/" + file |
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
| # decoder filenames from cp1251 to ut8 | |
| # date: 2018-12-25, author: https://github.com/lysenko-sergey-developer | |
| import os | |
| files = os.listdir(path=".") | |
| for file in files: | |
| valid_utf8 = True | |
| try: | |
| result = file.encode("cp1251").decode("utf8") |