Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
module.exports = {
"env": {
"browser": true,
"es6": true
"es6": true,
"amd":true
},
"extends": "eslint:recommended",
"globals": {
Expand Down
43 changes: 7 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,8 @@
## Welcome to GitHub Pages
| Name & Surname | kyu | Link |
| ------------- | ------------- | ------------- |
| Fedyna Stas | 8 | https://www.codewars.com/kata/keep-hydrated-1 |
| ^ | 8 | https://www.codewars.com/kata/pole-vault-starting-marks |
| ^ | 7 | https://www.codewars.com/kata/sum-of-a-sequence |
| ^ | 6 | https://www.codewars.com/kata/floating-point-approximation-i |
| ^ | 5 | https://www.codewars.com/kata/artificial-rain |

You can use the [editor on GitHub](https://github.com/lv-411-nodejs/codeWarsTasks/edit/master/README.md) to maintain and preview the content for your website in Markdown files.

Whenever you commit to this repository, GitHub Pages will run [Jekyll](https://jekyllrb.com/) to rebuild the pages in your site, from the content in your Markdown files.

### Markdown

Markdown is a lightweight and easy-to-use syntax for styling your writing. It includes conventions for

```markdown
Syntax highlighted code block

# Header 1
## Header 2
### Header 3

- Bulleted
- List

1. Numbered
2. List

**Bold** and _Italic_ and `Code` text

[Link](url) and ![Image](src)
```

For more details see [GitHub Flavored Markdown](https://guides.github.com/features/mastering-markdown/).

### Jekyll Themes

Your Pages site will use the layout and styles from the Jekyll theme you have selected in your [repository settings](https://github.com/lv-411-nodejs/codeWarsTasks/settings). The name of this theme is saved in the Jekyll `_config.yml` configuration file.

### Support or Contact

Having trouble with Pages? Check out our [documentation](https://help.github.com/categories/github-pages-basics/) or [contact support](https://github.com/contact) and we’ll help you sort it out.
15 changes: 13 additions & 2 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
require("amd-loader");
var msg = require('./tasks/template');
msg.print("run!");

var kyu8_1=require('./tasks/8_kyu');
console.log(kyu8_1.litres(3));
console.log(kyu8_1.startingMark(1.52));

var kyu7=require('./tasks/7_kyu');
console.log(kyu7.sequenceSum(1, 5, 1));

var kyu6=require('./tasks/6_kyu');
console.log(kyu6.approximationPoint(1e-15));

var kyu5=require('./tasks/5_kyu');
console.log(kyu5.artificialRain([4,5,6,10]));
53 changes: 53 additions & 0 deletions tasks/5_kyu.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
define(function () {
return {
artificialRain: function(garden){
const answers = [];

const checkLeft = (position) => {
if(position > 0) {
let sum = 0;
for (let i = position; i >= 0; i--) {
if(garden[i-1] <= garden[i]){
sum++
} else {
break;
}
}
return sum;

} else {
return 0;
}
}

const checkRight = (position) => {
if(position > 0) {
let sum = 0;
for (let i = position, max = garden.length; i < max; i++) {
if(garden[i+1] <= garden[i]){
sum++
} else {
break;
}
}
return sum;
} else {
return 0;
}
}

const checkPosition = (position) => {
const leftSum = checkLeft(position);
const rightSum = checkRight(position)
answers.push(1 + leftSum + rightSum);
}

for(let i = 0, max = garden.length; i < max; i++) {
checkPosition(i);
}

return Math.max(...answers)
}
};
})

7 changes: 7 additions & 0 deletions tasks/6_kyu.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
define(function () {
return {
approximationPoint: function(value){
return value / (1 + Math.sqrt(1 + value));
}
};
})
18 changes: 18 additions & 0 deletions tasks/7_kyu.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
define(function () {
return {
sequenceSum: function sequenceSum( begin, end, step ){
if(begin > end){
return 0
}

else if(begin === end){
return begin
}

else{
return begin + sequenceSum(begin += step, end, step)
}
}
};
})

11 changes: 11 additions & 0 deletions tasks/8_kyu.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
define(function () {
return {
litres: function(time){ return Math.floor(time * 0.5) },

startingMark: function(bodyHeight){
const diff = (10.67 - 9.45) / (1.83 - 1.52);
return Math.round((10.67 + diff * bodyHeight - diff * 1.83) * 100) / 100;
}
};
})

8 changes: 1 addition & 7 deletions tasks/template.js
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
define(function () {
return {
print: function(msg) {
console.log(msg);
}
};
});