From 5347cf8cf63743aa111dfa46005250e60234436c Mon Sep 17 00:00:00 2001 From: Ruslan Date: Wed, 15 May 2019 21:48:16 +0300 Subject: [PATCH 1/3] add first commit(tasks+table) --- README.md | 44 +++++++------------------------------------- tasks/5_kyu.js | 10 ++++++++++ tasks/6_kyu.js | 11 +++++++++++ tasks/7_kyu.js | 10 ++++++++++ tasks/8_kyu.js | 10 ++++++++++ 5 files changed, 48 insertions(+), 37 deletions(-) diff --git a/README.md b/README.md index c6f66a5..83f9be6 100644 --- a/README.md +++ b/README.md @@ -1,37 +1,7 @@ -## Welcome to GitHub Pages - -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. +| Name & Surname | kyu | Link | +| ------------- | ------------- | ------------- | +| Ners Ruslan | 8 | https://www.codewars.com/kata/heads-and-legs | +| ^ | 8 | https://www.codewars.com/kata/short-long-short | +| ^ | 7 | https://www.codewars.com/kata/triple-shiftian-numbers | +| ^ | 6 | https://www.codewars.com/kata/bouncing-balls/ | +| ^ | 5 | https://www.codewars.com/kata/product-of-consecutive-fib-numbers/python | diff --git a/tasks/5_kyu.js b/tasks/5_kyu.js index e69de29..c08f89f 100644 --- a/tasks/5_kyu.js +++ b/tasks/5_kyu.js @@ -0,0 +1,10 @@ +const productFib = (prod) => { + let a = 0, b = 1, c = 1; + while((a * b) !== prod) { + if(a * b > prod) return [a, b, false]; + c = a + b; + a = b; + b = c; + } + return [a, b, true] +} diff --git a/tasks/6_kyu.js b/tasks/6_kyu.js index e69de29..1762345 100644 --- a/tasks/6_kyu.js +++ b/tasks/6_kyu.js @@ -0,0 +1,11 @@ +const bouncingBall = (h, bounce, window) => { + if(h > 0 && bounce > 0 && bounce < 1) { + let count = 0; + while(h > window) { + h *= bounce; + count += 2; + } + return count - 1; + } + return -1; +} diff --git a/tasks/7_kyu.js b/tasks/7_kyu.js index e69de29..70de862 100644 --- a/tasks/7_kyu.js +++ b/tasks/7_kyu.js @@ -0,0 +1,10 @@ +// Triple Shiftian Numbers +const tripleShiftian = (base,n) => { + if(n < 3) return base[n]; + else { + for(let i = 3; i <= n; i++) + base.push(4 * base[i - 1] - 5 * base[i - 2] + 3 * base[i - 3]); + + return base[n]; + } +} diff --git a/tasks/8_kyu.js b/tasks/8_kyu.js index e69de29..3ec973b 100644 --- a/tasks/8_kyu.js +++ b/tasks/8_kyu.js @@ -0,0 +1,10 @@ +// Heads and Legs +const animals = (heads, legs) => { + const cows = (legs - heads * 2) / 2 ; + const chickens = heads - cows; + if( cows > heads || (cows ^ 0) !== cows || chickens > heads || (chickens ^ 0) !== chickens ) return "No solutions"; + else return [chickens, cows]; +} + +// Short Long Short +const solution = (a , b) => a.length > b.length ? b + a + b : a + b + a; From da7179b8981af8ca51781ffc1c703d3347040b82 Mon Sep 17 00:00:00 2001 From: Ruslan Date: Thu, 16 May 2019 17:43:13 +0300 Subject: [PATCH 2/3] fix errors for eslint --- tasks/5_kyu.js | 1 + tasks/6_kyu.js | 1 + tasks/7_kyu.js | 1 + tasks/8_kyu.js | 3 +++ 4 files changed, 6 insertions(+) diff --git a/tasks/5_kyu.js b/tasks/5_kyu.js index c08f89f..e28845b 100644 --- a/tasks/5_kyu.js +++ b/tasks/5_kyu.js @@ -8,3 +8,4 @@ const productFib = (prod) => { } return [a, b, true] } +productFib(5); diff --git a/tasks/6_kyu.js b/tasks/6_kyu.js index 1762345..93ec16e 100644 --- a/tasks/6_kyu.js +++ b/tasks/6_kyu.js @@ -9,3 +9,4 @@ const bouncingBall = (h, bounce, window) => { } return -1; } +bouncingBall(50,0.6,5); diff --git a/tasks/7_kyu.js b/tasks/7_kyu.js index 70de862..fb5cbd1 100644 --- a/tasks/7_kyu.js +++ b/tasks/7_kyu.js @@ -8,3 +8,4 @@ const tripleShiftian = (base,n) => { return base[n]; } } +tripleShiftian(3, 5); diff --git a/tasks/8_kyu.js b/tasks/8_kyu.js index 3ec973b..ee0af60 100644 --- a/tasks/8_kyu.js +++ b/tasks/8_kyu.js @@ -8,3 +8,6 @@ const animals = (heads, legs) => { // Short Long Short const solution = (a , b) => a.length > b.length ? b + a + b : a + b + a; + +animals(12,24); +solution('aa','b'); From f59409d971796c61dc8f9476914e388fb7225489 Mon Sep 17 00:00:00 2001 From: Ruslan Date: Thu, 16 May 2019 23:39:43 +0300 Subject: [PATCH 3/3] add default require & fixed amd --- .eslintrc.js | 3 ++- main.js | 15 +++++++++++++-- tasks/5_kyu.js | 25 ++++++++++++++----------- tasks/6_kyu.js | 27 +++++++++++++++------------ tasks/7_kyu.js | 24 +++++++++++++----------- tasks/8_kyu.js | 24 +++++++++++------------- tasks/template.js | 7 ------- 7 files changed, 68 insertions(+), 57 deletions(-) delete mode 100644 tasks/template.js diff --git a/.eslintrc.js b/.eslintrc.js index edadc67..d969a52 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 index c4c03e6..8889c2e 100644 --- a/main.js +++ b/main.js @@ -1,3 +1,14 @@ require("amd-loader"); -var msg = require('./tasks/template'); -msg.print("run!"); + +const kyu_8 = require('./tasks/8_kyu'); +console.log(kyu_8.animals(12,24)); +console.log(kyu_8.solution('get', 'beer')); + +const kyu_7 = require('./tasks/7_kyu'); +console.log(kyu_7.tripleShiftian([1,1,1],24)); + +const kyu_6 = require('./tasks/6_kyu'); +console.log(kyu_6.bouncingBall(12, 0.66, 2)); + +const kyu_5 = require('./tasks/5_kyu'); +console.log(kyu_5.productFibonacci(65)); diff --git a/tasks/5_kyu.js b/tasks/5_kyu.js index e28845b..586ad77 100644 --- a/tasks/5_kyu.js +++ b/tasks/5_kyu.js @@ -1,11 +1,14 @@ -const productFib = (prod) => { - let a = 0, b = 1, c = 1; - while((a * b) !== prod) { - if(a * b > prod) return [a, b, false]; - c = a + b; - a = b; - b = c; - } - return [a, b, true] -} -productFib(5); +define(function () { + return { + productFibonacci: prod => { + let a = 0, b = 1, c = 1; + while((a * b) !== prod) { + if(a * b > prod) return [a, b, false]; + c = a + b; + a = b; + b = c; + } + return [a, b, true] + } + }; +}); diff --git a/tasks/6_kyu.js b/tasks/6_kyu.js index 93ec16e..c3d1c94 100644 --- a/tasks/6_kyu.js +++ b/tasks/6_kyu.js @@ -1,12 +1,15 @@ -const bouncingBall = (h, bounce, window) => { - if(h > 0 && bounce > 0 && bounce < 1) { - let count = 0; - while(h > window) { - h *= bounce; - count += 2; - } - return count - 1; - } - return -1; -} -bouncingBall(50,0.6,5); +define(function () { + return { + bouncingBall: (h, bounce, window) => { + if(h > 0 && bounce > 0 && bounce < 1) { + let count = 0; + while(h > window) { + h *= bounce; + count += 2; + } + return count - 1; + } + return -1; + } + }; +}); diff --git a/tasks/7_kyu.js b/tasks/7_kyu.js index fb5cbd1..bd6312e 100644 --- a/tasks/7_kyu.js +++ b/tasks/7_kyu.js @@ -1,11 +1,13 @@ -// Triple Shiftian Numbers -const tripleShiftian = (base,n) => { - if(n < 3) return base[n]; - else { - for(let i = 3; i <= n; i++) - base.push(4 * base[i - 1] - 5 * base[i - 2] + 3 * base[i - 3]); - - return base[n]; - } -} -tripleShiftian(3, 5); +define(function () { + return { + tripleShiftian: (base,n) => { + if(n < 3) return base[n]; + else { + for(let i = 3; i <= n; i++) + base.push(4 * base[i - 1] - 5 * base[i - 2] + 3 * base[i - 3]); + + return base[n]; + } + } + }; +}); diff --git a/tasks/8_kyu.js b/tasks/8_kyu.js index ee0af60..0bcb40b 100644 --- a/tasks/8_kyu.js +++ b/tasks/8_kyu.js @@ -1,13 +1,11 @@ -// Heads and Legs -const animals = (heads, legs) => { - const cows = (legs - heads * 2) / 2 ; - const chickens = heads - cows; - if( cows > heads || (cows ^ 0) !== cows || chickens > heads || (chickens ^ 0) !== chickens ) return "No solutions"; - else return [chickens, cows]; -} - -// Short Long Short -const solution = (a , b) => a.length > b.length ? b + a + b : a + b + a; - -animals(12,24); -solution('aa','b'); +define(function () { + return { + animals: (heads, legs) => { + const cows = (legs - heads * 2) / 2 ; + const chickens = heads - cows; + if( cows > heads || (cows ^ 0) !== cows || chickens > heads || (chickens ^ 0) !== chickens ) return "No solutions"; + else return [chickens, cows]; + }, + solution: (a , b) => a.length > b.length ? b + a + b : a + b + a + }; +}); diff --git a/tasks/template.js b/tasks/template.js deleted file mode 100644 index 4d24ed8..0000000 --- a/tasks/template.js +++ /dev/null @@ -1,7 +0,0 @@ -define(function () { - return { - print: function(msg) { - console.log(msg); - } - }; -}); \ No newline at end of file