Skip to content
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
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
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"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[![Brest Rolling Scopes](http://brest.rollingscopes.com/images/logo_rs_text.svg)](http://brest.rollingscopes.com/)
#Brest Rolling Scopes School
## Javascript Assignments [![Build Status](https://travis-ci.org/AisBrestEDU/js-assignments.svg?branch=master)](https://travis-ci.org/AisBrestEDU/js-assignments)
## Javascript Assignments [![Build Status](https://travis-ci.org/Vpartyzan/js-assignments.svg?branch=master)](https://travis-ci.org/Vpartyzan/js-assignments)

Yet another javascript assignments. There are a lot of interactive javascript resources for beginners, but most of them are online and do not cover the modern programming workflow. There are some excellent training resources on github (https://github.com/rmurphey/js-assessment, https://github.com/mrdavidlaing/javascript-koans, https://github.com/vasanthk/js-bits etc) but they are not exactly simulate the everyday programming process. So the motivation of this project is to show TDD process in the wild to the beginners. Assingment tests are implemented in various ways to feel a difference and gain the experience what manner is good, what is bad and what is ugly.

Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"devDependencies": {
"mocha": "^2.3.4"
},
"repository" : {
"type" : "git",
"url" : "https://github.com/rolling-scopes-school/js-assignments.git"
"repository": {
"type": "git",
"url": "https://github.com/rolling-scopes-school/js-assignments.git"
}
}
83 changes: 76 additions & 7 deletions task/07-yield-tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,19 @@
*
*/
function* get99BottlesOfBeer() {
throw new Error('Not implemented');

for (let i = 99; i>2; i--) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spaces around operators

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.'

}


Expand All @@ -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;
}

}


Expand Down Expand Up @@ -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
Expand All @@ -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++;
}
}


Expand All @@ -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);
}
}
}

/**
Expand All @@ -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));
});
Copy link
Collaborator

Choose a reason for hiding this comment

The 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());
}


Expand Down