diff --git a/.eslintrc.js b/.eslintrc.js index edadc67..580e0ec 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,7 +1,8 @@ module.exports = { "env": { "browser": true, - "es6": true + "es6": true, + "amd":true }, "extends": "eslint:recommended", "globals": { diff --git a/README.md b/README.md index c6f66a5..e38271f 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/main.js b/main.js index c4c03e6..50fc067 100644 --- a/main.js +++ b/main.js @@ -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])); diff --git a/tasks/5_kyu.js b/tasks/5_kyu.js index e69de29..49710e1 100644 --- a/tasks/5_kyu.js +++ b/tasks/5_kyu.js @@ -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) + } + }; +}) + diff --git a/tasks/6_kyu.js b/tasks/6_kyu.js index e69de29..52321ee 100644 --- a/tasks/6_kyu.js +++ b/tasks/6_kyu.js @@ -0,0 +1,7 @@ +define(function () { + return { + approximationPoint: function(value){ + return value / (1 + Math.sqrt(1 + value)); + } + }; +}) diff --git a/tasks/7_kyu.js b/tasks/7_kyu.js index e69de29..6c06e29 100644 --- a/tasks/7_kyu.js +++ b/tasks/7_kyu.js @@ -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) + } + } + }; +}) + diff --git a/tasks/8_kyu.js b/tasks/8_kyu.js index e69de29..d00aa59 100644 --- a/tasks/8_kyu.js +++ b/tasks/8_kyu.js @@ -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; + } + }; +}) + diff --git a/tasks/template.js b/tasks/template.js index 4d24ed8..8b13789 100644 --- a/tasks/template.js +++ b/tasks/template.js @@ -1,7 +1 @@ -define(function () { - return { - print: function(msg) { - console.log(msg); - } - }; -}); \ No newline at end of file +