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 _ = require('lodash'); | |
| function series(arr, fn) { | |
| let result = []; | |
| return _.reduce(arr, (acc, item) => { | |
| acc = acc | |
| .then(() => fn(item)) | |
| .then(res => result.push(res)); | |
| return acc; |
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 allWords = require('russian-words'); | |
| function getCubesLettersHeap(cubes) { | |
| return cubes.reduce((acc, cube) => { | |
| const letters = cube.split(''); | |
| letters.forEach(letter => { | |
| acc[letter] = acc[letter]? acc[letter] + 1 : 1; | |
| }); | |
| return acc; | |
| }, {}); |
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 getValidIpAddresses(str) { | |
| let result = []; | |
| for (let i = 1; i < str.length; i++) { | |
| let first = str.slice(0, i); | |
| if (first > 255) continue; | |
| let withoutFirst = str.slice(i); | |
| for (let j = 1; j < withoutFirst.length; j++) { | |
| let second = withoutFirst.slice(0, j); | |
| if (second > 255) continue; | |
| let withoutFirstSecond = withoutFirst.slice(j); |
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 padding(depth) { | |
| return new Array(depth).fill(' ').join(''); | |
| } | |
| function walk(node, depth) { | |
| if (node.nodeType === 1) { | |
| console.log(padding(depth) + node.tagName); | |
| let children = Array.from(node.childNodes); | |
| children.forEach(item => walk(item, depth + 1)); | |
| } else if (node.nodeType === 3) { |
OlderNewer