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 Tree = ({ data }) => { | |
| return data?.map((p: NumberingBranch) => { | |
| return ( | |
| <div key={p.id} className="NumberingList__Parent"> | |
| <div> | |
| <div className="NumberingList__ItemWrapper"> | |
| <span className="NumberingList__Title">{p.data.text}</span> | |
| </div> | |
| </div> | |
| {p.children.length > 0 && <Tree data={p.children} />} |
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 makeTree = (paragraphs) => { | |
| const findParentLevel = (levels, level) => { | |
| if (levels[level]) { | |
| return level; | |
| } | |
| return findParentLevel(levels, level - 1); | |
| }; | |
| const tree = paragraphs.reduce( | |
| (acc, p) => { |
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
| public makeFlatNumberingArray = (paragraphs) => { | |
| const resultArr = []; | |
| let levelData = null; | |
| for (let i = 0; i < paragraphs.length; i++) { | |
| const curr = paragraphs[i]; | |
| let level = 0; | |
| let parentId = null; | |
| let levelString = curr.data.isListItem ? curr.data.listItem.listString : hasNumbering(curr.data.text)[0]; | |
| for (let j = i - 1; j >= 0; 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
| const createDataTree = dataset => { | |
| let hashTable = Object.create(null) | |
| dataset.forEach( aData => hashTable[aData.id] = { ...aData, childNodes : [] } ) | |
| let dataTree = [] | |
| dataset.forEach( aData => { | |
| if( Number.isInteger(aData.parentId)) { | |
| hashTable[aData.parentId].childNodes.push(hashTable[aData.id]) | |
| } else { | |
| dataTree.push(hashTable[aData.id]) | |
| } |
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 input = [ | |
| { type: "dir", name: "src", contents: | |
| [ | |
| { type: "dir", name: "doc", contents: | |
| [ | |
| { type: "file", name: "TOC.md" }, | |
| { type: "file", name: "css.md" }, | |
| { type: "file", name: "extend.md" }, | |
| { type: "file", name: "faq.md" }, | |
| { type: "file", name: "html.md" }, |
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
| import { EventEmitter } from 'eventemitter3'; | |
| type ListenerFn = (...args: Array<any>) => void; | |
| class EventBus { | |
| public eventEmitter: EventEmitter; | |
| /** | |
| * Initiate the event emitter | |
| */ | |
| constructor() { |
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
| // Task 1. Children on the Flight. | |
| // We are building Web application for the airlines. | |
| // There is a page where we show list of passengers | |
| // for the given flights. | |
| // There is an age restriction: | |
| // All children younger than 5 years old should have | |
| // at least one adult parent or guardian. | |
| // Parent/guardian should be at least 18 years old. | |
| // We want to highlight all children who are not | |
| // allowed to be on the flight. |
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
| // Task 2. Maximum Budget Problem. | |
| // We want to find out the most expensive trip combinations that can be purchased with a given budget. Given the price lists for two cities and a budget, find the total cost to buy them. | |
| // Return maximum budget that can be spent, or -1 if it is not possible to buy both trips. | |
| // Example 1 | |
| // Total trip budget = 10 | |
| // Paris trips = [3, 1] | |
| // Barcelona trips = [5, 2, 8] | |
| // Sample Output: 9 |
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
| // Task 3. Price of simple parts | |
| // We are selling computer hardware. We have products assembled from parts. | |
| // For example PC is build from motherboard, cpu, hard drive, etc. Some parts are simple: they have no sub parts like CPU. | |
| // When the part has subparts it is not simple. For example PC body has different subparts like covers, screws, etc. | |
| // Every part has price. | |
| // Task: | |
| // For a given list of parts find total price of the all simple parts. |
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 gArray = () => { | |
| var array = []; | |
| const a = (value) => { | |
| array.push(value); | |
| return array; | |
| } | |
| return a; | |
| }; | |
| const b = gArray(); |