forked from rolling-scopes-school/js-assignments
-
Notifications
You must be signed in to change notification settings - Fork 194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
7Task.Max.Cichanau #873
Draft
Vpartyzan
wants to merge
5
commits into
AisBrestEDU:master
Choose a base branch
from
Vpartyzan:task7
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
7Task.Max.Cichanau #873
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
language: node_js | ||
node_js: | ||
- "5.10.0" | ||
- "12.16.2" |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,19 @@ | |
* | ||
*/ | ||
function* get99BottlesOfBeer() { | ||
throw new Error('Not implemented'); | ||
|
||
for (let i = 99; i>2; i--) { | ||
yield `${i} bottles of beer on the wall, ${i} bottles of beer.`; | ||
yield `Take one down and pass it around, ${i-1} bottles of beer on the wall.`; | ||
} | ||
|
||
yield `2 bottles of beer on the wall, 2 bottles of beer.`; | ||
yield `Take one down and pass it around, 1 bottle of beer on the wall.` | ||
yield '1 bottle of beer on the wall, 1 bottle of beer.' | ||
yield 'Take one down and pass it around, no more bottles of beer on the wall.' | ||
yield 'No more bottles of beer on the wall, no more bottles of beer.' | ||
yield 'Go to the store and buy some more, 99 bottles of beer on the wall.' | ||
|
||
} | ||
|
||
|
||
|
@@ -47,7 +59,18 @@ function* get99BottlesOfBeer() { | |
* | ||
*/ | ||
function* getFibonacciSequence() { | ||
throw new Error('Not implemented'); | ||
let prev = 0, | ||
curr = 1; | ||
yield prev; | ||
yield curr; | ||
|
||
while(true) { | ||
let sum = prev + curr; | ||
yield sum; | ||
prev = curr; | ||
curr = sum; | ||
} | ||
|
||
} | ||
|
||
|
||
|
@@ -82,9 +105,17 @@ function* getFibonacciSequence() { | |
* | ||
*/ | ||
function* depthTraversalTree(root) { | ||
throw new Error('Not implemented'); | ||
} | ||
let nodes= [root]; | ||
|
||
while(nodes.length){ | ||
let root = nodes.pop(); | ||
yield root; | ||
|
||
if (root.children) { | ||
nodes.push(...root.children.reverse()); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Traverses a tree using the breadth-first strategy | ||
|
@@ -108,7 +139,19 @@ function* depthTraversalTree(root) { | |
* | ||
*/ | ||
function* breadthTraversalTree(root) { | ||
throw new Error('Not implemented'); | ||
let arr = [root], | ||
index = 0; | ||
|
||
while (arr.length !== index){ | ||
root = arr[index]; | ||
yield root; | ||
|
||
if (root.children){ | ||
arr.push(...root.children); | ||
} | ||
|
||
index++; | ||
} | ||
} | ||
|
||
|
||
|
@@ -126,7 +169,23 @@ function* breadthTraversalTree(root) { | |
* [ 1, 3, 5, ... ], [ -1 ] => [ -1, 1, 3, 5, ...] | ||
*/ | ||
function* mergeSortedSequences(source1, source2) { | ||
throw new Error('Not implemented'); | ||
let s1 = source1(), | ||
s2 = source2(); | ||
|
||
|
||
while (true) { | ||
const val1 = s1.next(), | ||
val2 = s2.next(); | ||
|
||
if (val1.done) { | ||
yield val2.value; | ||
} else if (val2.done) { | ||
yield val1.value; | ||
} else { | ||
yield Math.min(val1.value, val2.value); | ||
yield Math.max(val1.value, val2.value); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
|
@@ -145,7 +204,17 @@ function* mergeSortedSequences(source1, source2) { | |
* Most popular implementation of the logic in npm https://www.npmjs.com/package/co | ||
*/ | ||
function async(generator) { | ||
throw new Error('Not implemented'); | ||
const gen = generator(); | ||
|
||
const handle = (res) => { | ||
return (res.done) | ||
? Promise.resolve(res.value) | ||
: Promise.resolve(res.value).then((res) => { | ||
return handle(gen.next(res)); | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. avoid this code style, if-else is more readable than multiple conditional operators ? : |
||
} | ||
|
||
return handle(gen.next()); | ||
} | ||
|
||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
spaces around operators