From 7ecc8af521a1a78ee3e52127e1a6aa66a4b5d79a Mon Sep 17 00:00:00 2001 From: StanislavFedyna Date: Thu, 16 May 2019 13:09:23 +0300 Subject: [PATCH 1/6] added tasks & own part for table --- README.md | 43 +++++++------------------------------------ tasks/5_kyu.js | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ tasks/6_kyu.js | 4 ++++ tasks/7_kyu.js | 15 +++++++++++++++ tasks/8_kyu.js | 9 +++++++++ 5 files changed, 85 insertions(+), 36 deletions(-) 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/tasks/5_kyu.js b/tasks/5_kyu.js index e69de29..4759af1 100644 --- a/tasks/5_kyu.js +++ b/tasks/5_kyu.js @@ -0,0 +1,50 @@ +function artificialRain(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..f13b6b8 100644 --- a/tasks/6_kyu.js +++ b/tasks/6_kyu.js @@ -0,0 +1,4 @@ +const approximationPoint = (value) => { + return value / (1 + Math.sqrt(1 + value)); +} + diff --git a/tasks/7_kyu.js b/tasks/7_kyu.js index e69de29..ff508c0 100644 --- a/tasks/7_kyu.js +++ b/tasks/7_kyu.js @@ -0,0 +1,15 @@ +const 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..ba5eef2 100644 --- a/tasks/8_kyu.js +++ b/tasks/8_kyu.js @@ -0,0 +1,9 @@ +const litres = (time) => { + return Math.floor(time * 0.5) +} + +const startingMark = (bodyHeight) => { + const diff = (10.67 - 9.45) / (1.83 - 1.52); + return Math.round((10.67 + diff * bodyHeight - diff * 1.83) * 100) / 100; +} + From c61e726fafb4f5e68528ac6f3853dc0925543a5f Mon Sep 17 00:00:00 2001 From: Stanislav Date: Thu, 16 May 2019 17:38:21 +0300 Subject: [PATCH 2/6] updated tasks, fixed problem --- tasks/5_kyu.js | 2 ++ tasks/6_kyu.js | 2 ++ tasks/7_kyu.js | 2 ++ tasks/8_kyu.js | 5 +++++ 4 files changed, 11 insertions(+) diff --git a/tasks/5_kyu.js b/tasks/5_kyu.js index 4759af1..c6b624d 100644 --- a/tasks/5_kyu.js +++ b/tasks/5_kyu.js @@ -48,3 +48,5 @@ function artificialRain(garden) { return Math.max(...answers) } +artificialRain([4,5,6,10]); + diff --git a/tasks/6_kyu.js b/tasks/6_kyu.js index f13b6b8..997620a 100644 --- a/tasks/6_kyu.js +++ b/tasks/6_kyu.js @@ -2,3 +2,5 @@ const approximationPoint = (value) => { return value / (1 + Math.sqrt(1 + value)); } +approximationPoint(1e-15); + diff --git a/tasks/7_kyu.js b/tasks/7_kyu.js index ff508c0..cd866f2 100644 --- a/tasks/7_kyu.js +++ b/tasks/7_kyu.js @@ -13,3 +13,5 @@ const sequenceSum = (begin, end, step) => { } } +sequenceSum(1,5,1); + diff --git a/tasks/8_kyu.js b/tasks/8_kyu.js index ba5eef2..31956be 100644 --- a/tasks/8_kyu.js +++ b/tasks/8_kyu.js @@ -1,9 +1,14 @@ const litres = (time) => { return Math.floor(time * 0.5) } +litres(3); const startingMark = (bodyHeight) => { const diff = (10.67 - 9.45) / (1.83 - 1.52); return Math.round((10.67 + diff * bodyHeight - diff * 1.83) * 100) / 100; } +startingMark(1.52); + + + From 91c7980c32e226290971cb3ce92469c3ab8ef6de Mon Sep 17 00:00:00 2001 From: Stanislav Date: Fri, 17 May 2019 08:29:53 +0300 Subject: [PATCH 3/6] added define --- .eslintrc.js | 3 ++- main.js | 16 ++++++++++++++++ tasks/5_kyu.js | 13 +++++++------ tasks/6_kyu.js | 11 +++++++---- tasks/7_kyu.js | 31 ++++++++++++++++++------------- tasks/8_kyu.js | 24 +++++++++++++----------- 6 files changed, 63 insertions(+), 35 deletions(-) create mode 100644 main.js 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/main.js b/main.js new file mode 100644 index 0000000..d3f0561 --- /dev/null +++ b/main.js @@ -0,0 +1,16 @@ +require("amd-loader"); + +var kyu8_1=require('./tasks/8_kyu'); +console.log(kyu8_1.litres(3)); + +var kyu8_2=require('./tasks/8_kyu'); +console.log(kyu8_2.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])); \ No newline at end of file diff --git a/tasks/5_kyu.js b/tasks/5_kyu.js index c6b624d..49710e1 100644 --- a/tasks/5_kyu.js +++ b/tasks/5_kyu.js @@ -1,6 +1,7 @@ -function artificialRain(garden) { - - const answers = []; +define(function () { + return { + artificialRain: function(garden){ + const answers = []; const checkLeft = (position) => { if(position > 0) { @@ -46,7 +47,7 @@ function artificialRain(garden) { } return Math.max(...answers) -} - -artificialRain([4,5,6,10]); + } + }; +}) diff --git a/tasks/6_kyu.js b/tasks/6_kyu.js index 997620a..00b0397 100644 --- a/tasks/6_kyu.js +++ b/tasks/6_kyu.js @@ -1,6 +1,9 @@ -const approximationPoint = (value) => { - return value / (1 + Math.sqrt(1 + value)); -} +define(function () { + return { + approximationPoint: function(value){ + return value / (1 + Math.sqrt(1 + value)); + } + }; +}) -approximationPoint(1e-15); diff --git a/tasks/7_kyu.js b/tasks/7_kyu.js index cd866f2..323a930 100644 --- a/tasks/7_kyu.js +++ b/tasks/7_kyu.js @@ -1,17 +1,22 @@ -const sequenceSum = (begin, end, step) => { - - if(begin > end){ - return 0 - } - - else if(begin === end){ - return begin +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) + } } + }; +}) + + - else{ - return begin + sequenceSum(begin += step, end, step) - } -} -sequenceSum(1,5,1); diff --git a/tasks/8_kyu.js b/tasks/8_kyu.js index 31956be..424987c 100644 --- a/tasks/8_kyu.js +++ b/tasks/8_kyu.js @@ -1,14 +1,16 @@ -const litres = (time) => { - return Math.floor(time * 0.5) -} -litres(3); - -const startingMark = (bodyHeight) => { - const diff = (10.67 - 9.45) / (1.83 - 1.52); - return Math.round((10.67 + diff * bodyHeight - diff * 1.83) * 100) / 100; -} - -startingMark(1.52); +define(function () { + return { + litres: function(time){Math.floor(time * 0.5)} + }; +}) +define(function () { + return { + 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; + } + }; +}) From 7be7c6f17231615a6c2ceb00ff75c9851c9e45bb Mon Sep 17 00:00:00 2001 From: Stanislav Date: Fri, 17 May 2019 08:54:39 +0300 Subject: [PATCH 4/6] test --- tasks/6_kyu.js | 2 -- tasks/7_kyu.js | 4 ---- tasks/8_kyu.js | 1 - 3 files changed, 7 deletions(-) diff --git a/tasks/6_kyu.js b/tasks/6_kyu.js index 00b0397..52321ee 100644 --- a/tasks/6_kyu.js +++ b/tasks/6_kyu.js @@ -5,5 +5,3 @@ define(function () { } }; }) - - diff --git a/tasks/7_kyu.js b/tasks/7_kyu.js index 323a930..6c06e29 100644 --- a/tasks/7_kyu.js +++ b/tasks/7_kyu.js @@ -16,7 +16,3 @@ define(function () { }; }) - - - - diff --git a/tasks/8_kyu.js b/tasks/8_kyu.js index 424987c..d555413 100644 --- a/tasks/8_kyu.js +++ b/tasks/8_kyu.js @@ -13,4 +13,3 @@ define(function () { }; }) - From 8fc6474a6a8b1787f7991fc6285f9b9e8a09e2ef Mon Sep 17 00:00:00 2001 From: Stanislav Date: Fri, 17 May 2019 11:34:08 +0300 Subject: [PATCH 5/6] fixed problem --- main.js | 4 +--- tasks/8_kyu.js | 8 ++------ 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/main.js b/main.js index 02d61f7..50fc067 100644 --- a/main.js +++ b/main.js @@ -2,9 +2,7 @@ require("amd-loader"); var kyu8_1=require('./tasks/8_kyu'); console.log(kyu8_1.litres(3)); - -var kyu8_2=require('./tasks/8_kyu'); -console.log(kyu8_2.startingMark(1.52)); +console.log(kyu8_1.startingMark(1.52)); var kyu7=require('./tasks/7_kyu'); console.log(kyu7.sequenceSum(1, 5, 1)); diff --git a/tasks/8_kyu.js b/tasks/8_kyu.js index d555413..d00aa59 100644 --- a/tasks/8_kyu.js +++ b/tasks/8_kyu.js @@ -1,11 +1,7 @@ define(function () { return { - litres: function(time){Math.floor(time * 0.5)} - }; -}) - -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; From eacda2fd0ab7a1be3ab5a42d827bd021c95c1a31 Mon Sep 17 00:00:00 2001 From: Stanislav Date: Fri, 17 May 2019 11:47:06 +0300 Subject: [PATCH 6/6] deleted from template.js --- tasks/template.js | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) 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 +