From 1eb436485aa836c7688a041dab43fc5d9a0cc61e Mon Sep 17 00:00:00 2001 From: MaxVoloskiy Date: Wed, 15 May 2019 22:15:20 +0300 Subject: [PATCH 01/21] added functions --- .gitignore | 3 +++ tasks/5_kyu.js | 16 ++++++++++++++++ tasks/6_kyu.js | 21 +++++++++++++++++++++ tasks/7_kyu.js | 7 +++++++ tasks/8_kyu.js | 20 ++++++++++++++++++++ 5 files changed, 67 insertions(+) diff --git a/.gitignore b/.gitignore index ad46b30..06e4732 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +# idea +.idea + # Logs logs *.log diff --git a/tasks/5_kyu.js b/tasks/5_kyu.js index e69de29..66b11a4 100644 --- a/tasks/5_kyu.js +++ b/tasks/5_kyu.js @@ -0,0 +1,16 @@ +function perimeter(n) { + return 4 * fibonacci(n); +} + +function fibonacci(n) { + + let init = 1; + let res = 1; + + for (let i = 0; i <= n; i++) { + let temp = res; + res += init; + init = temp; + } + return res - 1; +} diff --git a/tasks/6_kyu.js b/tasks/6_kyu.js index e69de29..93d3351 100644 --- a/tasks/6_kyu.js +++ b/tasks/6_kyu.js @@ -0,0 +1,21 @@ +function stockList(listOfArt, listOfCat) { + + if (!listOfArt.length || !listOfCat.length) { + return ''; + } + + let books = {}; + let result = []; + + listOfArt.forEach((book) => { + let [title, num] = book.split(" "); + books[title[0]] = books[title[0]] ? (books[title[0]] += Number(num)) : Number(num); + }); + + listOfCat.forEach((letter) => { + let num = books[letter] || 0; + result.push(`(${letter} : ${num})`); + }); + + return result.join` - `; +} \ No newline at end of file diff --git a/tasks/7_kyu.js b/tasks/7_kyu.js index e69de29..f797559 100644 --- a/tasks/7_kyu.js +++ b/tasks/7_kyu.js @@ -0,0 +1,7 @@ +function lockerRun(lockers){ + let open = []; + for (let i = 1; i * i <= lockers; i++) { + open.push(i * i); + } + return open; +} \ No newline at end of file diff --git a/tasks/8_kyu.js b/tasks/8_kyu.js index e69de29..96086b8 100644 --- a/tasks/8_kyu.js +++ b/tasks/8_kyu.js @@ -0,0 +1,20 @@ +function countPositivesSumNegatives(input) { + let positive = 0; + let negative = 0; + + if (input === [] || input === null || input < 1) + return []; + + for (let i=0; i 0){ + positive += 1; + } else { + negative += input[i] + } + } + return [positive, negative] +} + +function stringToNumber (str){ + return Number(str) +} \ No newline at end of file From 316d60abae8d25f5d9b2736897929f0083ffee21 Mon Sep 17 00:00:00 2001 From: MaxVoloskiy Date: Wed, 15 May 2019 22:28:50 +0300 Subject: [PATCH 02/21] added README --- README.md | 44 +++++++------------------------------------- 1 file changed, 7 insertions(+), 37 deletions(-) diff --git a/README.md b/README.md index c6f66a5..e39c4ce 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 | +| ------------- | ------------- | ------------- | +| Max Voloskiy | 8 | https://www.codewars.com/kata/count-of-positives-slash-sum-of-negatives | +| | 8 | https://www.codewars.com/kata/convert-a-string-to-a-number | +| | 7 | https://www.codewars.com/kata/slamming-lockers | +| | 6 | https://www.codewars.com/kata/help-the-bookseller | +| | 5 | https://www.codewars.com/kata/perimeter-of-squares-in-a-rectangle | \ No newline at end of file From 5c38db655294a960ce80b97237e77f1c57525d90 Mon Sep 17 00:00:00 2001 From: MaxVoloskiy Date: Wed, 15 May 2019 22:54:01 +0300 Subject: [PATCH 03/21] refactored files --- README.md | 2 +- tasks/6_kyu.js | 2 +- tasks/7_kyu.js | 2 +- tasks/8_kyu.js | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index e39c4ce..242633a 100644 --- a/README.md +++ b/README.md @@ -4,4 +4,4 @@ | | 8 | https://www.codewars.com/kata/convert-a-string-to-a-number | | | 7 | https://www.codewars.com/kata/slamming-lockers | | | 6 | https://www.codewars.com/kata/help-the-bookseller | -| | 5 | https://www.codewars.com/kata/perimeter-of-squares-in-a-rectangle | \ No newline at end of file +| | 5 | https://www.codewars.com/kata/perimeter-of-squares-in-a-rectangle | diff --git a/tasks/6_kyu.js b/tasks/6_kyu.js index 93d3351..c6831f4 100644 --- a/tasks/6_kyu.js +++ b/tasks/6_kyu.js @@ -18,4 +18,4 @@ function stockList(listOfArt, listOfCat) { }); return result.join` - `; -} \ No newline at end of file +} diff --git a/tasks/7_kyu.js b/tasks/7_kyu.js index f797559..b8a135d 100644 --- a/tasks/7_kyu.js +++ b/tasks/7_kyu.js @@ -4,4 +4,4 @@ function lockerRun(lockers){ open.push(i * i); } return open; -} \ No newline at end of file +} diff --git a/tasks/8_kyu.js b/tasks/8_kyu.js index 96086b8..9cf70f3 100644 --- a/tasks/8_kyu.js +++ b/tasks/8_kyu.js @@ -17,4 +17,4 @@ function countPositivesSumNegatives(input) { function stringToNumber (str){ return Number(str) -} \ No newline at end of file +} From c20a7a914aa927fe68414cbdf52a3495fc5584c2 Mon Sep 17 00:00:00 2001 From: MaxVoloskiy Date: Wed, 15 May 2019 22:15:20 +0300 Subject: [PATCH 04/21] added functions --- .gitignore | 3 +++ tasks/5_kyu.js | 16 ++++++++++++++++ tasks/6_kyu.js | 21 +++++++++++++++++++++ tasks/7_kyu.js | 7 +++++++ tasks/8_kyu.js | 20 ++++++++++++++++++++ 5 files changed, 67 insertions(+) diff --git a/.gitignore b/.gitignore index 9972163..0e26ec7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +# idea +.idea + # Logs logs *.log diff --git a/tasks/5_kyu.js b/tasks/5_kyu.js index e69de29..66b11a4 100644 --- a/tasks/5_kyu.js +++ b/tasks/5_kyu.js @@ -0,0 +1,16 @@ +function perimeter(n) { + return 4 * fibonacci(n); +} + +function fibonacci(n) { + + let init = 1; + let res = 1; + + for (let i = 0; i <= n; i++) { + let temp = res; + res += init; + init = temp; + } + return res - 1; +} diff --git a/tasks/6_kyu.js b/tasks/6_kyu.js index e69de29..93d3351 100644 --- a/tasks/6_kyu.js +++ b/tasks/6_kyu.js @@ -0,0 +1,21 @@ +function stockList(listOfArt, listOfCat) { + + if (!listOfArt.length || !listOfCat.length) { + return ''; + } + + let books = {}; + let result = []; + + listOfArt.forEach((book) => { + let [title, num] = book.split(" "); + books[title[0]] = books[title[0]] ? (books[title[0]] += Number(num)) : Number(num); + }); + + listOfCat.forEach((letter) => { + let num = books[letter] || 0; + result.push(`(${letter} : ${num})`); + }); + + return result.join` - `; +} \ No newline at end of file diff --git a/tasks/7_kyu.js b/tasks/7_kyu.js index e69de29..f797559 100644 --- a/tasks/7_kyu.js +++ b/tasks/7_kyu.js @@ -0,0 +1,7 @@ +function lockerRun(lockers){ + let open = []; + for (let i = 1; i * i <= lockers; i++) { + open.push(i * i); + } + return open; +} \ No newline at end of file diff --git a/tasks/8_kyu.js b/tasks/8_kyu.js index e69de29..96086b8 100644 --- a/tasks/8_kyu.js +++ b/tasks/8_kyu.js @@ -0,0 +1,20 @@ +function countPositivesSumNegatives(input) { + let positive = 0; + let negative = 0; + + if (input === [] || input === null || input < 1) + return []; + + for (let i=0; i 0){ + positive += 1; + } else { + negative += input[i] + } + } + return [positive, negative] +} + +function stringToNumber (str){ + return Number(str) +} \ No newline at end of file From db2de12bb8698caf7ebc56c24cb0d752b23428cd Mon Sep 17 00:00:00 2001 From: MaxVoloskiy Date: Wed, 15 May 2019 22:28:50 +0300 Subject: [PATCH 05/21] added README --- README.md | 44 +++++++------------------------------------- 1 file changed, 7 insertions(+), 37 deletions(-) diff --git a/README.md b/README.md index c6f66a5..e39c4ce 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 | +| ------------- | ------------- | ------------- | +| Max Voloskiy | 8 | https://www.codewars.com/kata/count-of-positives-slash-sum-of-negatives | +| | 8 | https://www.codewars.com/kata/convert-a-string-to-a-number | +| | 7 | https://www.codewars.com/kata/slamming-lockers | +| | 6 | https://www.codewars.com/kata/help-the-bookseller | +| | 5 | https://www.codewars.com/kata/perimeter-of-squares-in-a-rectangle | \ No newline at end of file From 7943f4e5c21073439f709f73df1bb8a35d2e734e Mon Sep 17 00:00:00 2001 From: MaxVoloskiy Date: Wed, 15 May 2019 22:54:01 +0300 Subject: [PATCH 06/21] refactored files --- README.md | 2 +- tasks/6_kyu.js | 2 +- tasks/7_kyu.js | 2 +- tasks/8_kyu.js | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index e39c4ce..242633a 100644 --- a/README.md +++ b/README.md @@ -4,4 +4,4 @@ | | 8 | https://www.codewars.com/kata/convert-a-string-to-a-number | | | 7 | https://www.codewars.com/kata/slamming-lockers | | | 6 | https://www.codewars.com/kata/help-the-bookseller | -| | 5 | https://www.codewars.com/kata/perimeter-of-squares-in-a-rectangle | \ No newline at end of file +| | 5 | https://www.codewars.com/kata/perimeter-of-squares-in-a-rectangle | diff --git a/tasks/6_kyu.js b/tasks/6_kyu.js index 93d3351..c6831f4 100644 --- a/tasks/6_kyu.js +++ b/tasks/6_kyu.js @@ -18,4 +18,4 @@ function stockList(listOfArt, listOfCat) { }); return result.join` - `; -} \ No newline at end of file +} diff --git a/tasks/7_kyu.js b/tasks/7_kyu.js index f797559..b8a135d 100644 --- a/tasks/7_kyu.js +++ b/tasks/7_kyu.js @@ -4,4 +4,4 @@ function lockerRun(lockers){ open.push(i * i); } return open; -} \ No newline at end of file +} diff --git a/tasks/8_kyu.js b/tasks/8_kyu.js index 96086b8..9cf70f3 100644 --- a/tasks/8_kyu.js +++ b/tasks/8_kyu.js @@ -17,4 +17,4 @@ function countPositivesSumNegatives(input) { function stringToNumber (str){ return Number(str) -} \ No newline at end of file +} From 94d2ef467e45970b73d4e5f2aa54fc71c5896b8a Mon Sep 17 00:00:00 2001 From: MaxVoloskiy Date: Thu, 16 May 2019 17:26:37 +0300 Subject: [PATCH 07/21] run functions --- tasks/5_kyu.js | 2 ++ tasks/6_kyu.js | 2 ++ tasks/7_kyu.js | 2 ++ tasks/8_kyu.js | 4 ++++ 4 files changed, 10 insertions(+) diff --git a/tasks/5_kyu.js b/tasks/5_kyu.js index 66b11a4..3fb2a88 100644 --- a/tasks/5_kyu.js +++ b/tasks/5_kyu.js @@ -14,3 +14,5 @@ function fibonacci(n) { } return res - 1; } + +perimeter(10); \ No newline at end of file diff --git a/tasks/6_kyu.js b/tasks/6_kyu.js index c6831f4..b6d49c2 100644 --- a/tasks/6_kyu.js +++ b/tasks/6_kyu.js @@ -19,3 +19,5 @@ function stockList(listOfArt, listOfCat) { return result.join` - `; } + +stockList(["CBART 20", "CDXEF 50", "BKWRK 25", "BTSQZ 89", "DRTYM 60"], ["A", "B", "C", "W"]); \ No newline at end of file diff --git a/tasks/7_kyu.js b/tasks/7_kyu.js index b8a135d..16ff25e 100644 --- a/tasks/7_kyu.js +++ b/tasks/7_kyu.js @@ -5,3 +5,5 @@ function lockerRun(lockers){ } return open; } + +lockerRun(9); \ No newline at end of file diff --git a/tasks/8_kyu.js b/tasks/8_kyu.js index 9cf70f3..02194c6 100644 --- a/tasks/8_kyu.js +++ b/tasks/8_kyu.js @@ -15,6 +15,10 @@ function countPositivesSumNegatives(input) { return [positive, negative] } +countPositivesSumNegatives([-1, -2, -3, 3, 2, 1]); + function stringToNumber (str){ return Number(str) } + +stringToNumber("123"); \ No newline at end of file From 7ebd2930c2918fc3f064d908f170d7c1d2f1eab4 Mon Sep 17 00:00:00 2001 From: MaxVoloskiy Date: Thu, 16 May 2019 17:40:48 +0300 Subject: [PATCH 08/21] added empty line --- tasks/5_kyu.js | 2 +- tasks/6_kyu.js | 2 +- tasks/7_kyu.js | 2 +- tasks/8_kyu.js | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tasks/5_kyu.js b/tasks/5_kyu.js index 3fb2a88..27834fd 100644 --- a/tasks/5_kyu.js +++ b/tasks/5_kyu.js @@ -15,4 +15,4 @@ function fibonacci(n) { return res - 1; } -perimeter(10); \ No newline at end of file +perimeter(10); diff --git a/tasks/6_kyu.js b/tasks/6_kyu.js index b6d49c2..341d0a4 100644 --- a/tasks/6_kyu.js +++ b/tasks/6_kyu.js @@ -20,4 +20,4 @@ function stockList(listOfArt, listOfCat) { return result.join` - `; } -stockList(["CBART 20", "CDXEF 50", "BKWRK 25", "BTSQZ 89", "DRTYM 60"], ["A", "B", "C", "W"]); \ No newline at end of file +stockList(["CBART 20", "CDXEF 50", "BKWRK 25", "BTSQZ 89", "DRTYM 60"], ["A", "B", "C", "W"]); diff --git a/tasks/7_kyu.js b/tasks/7_kyu.js index 16ff25e..c1562ec 100644 --- a/tasks/7_kyu.js +++ b/tasks/7_kyu.js @@ -6,4 +6,4 @@ function lockerRun(lockers){ return open; } -lockerRun(9); \ No newline at end of file +lockerRun(9); diff --git a/tasks/8_kyu.js b/tasks/8_kyu.js index 02194c6..62f87ab 100644 --- a/tasks/8_kyu.js +++ b/tasks/8_kyu.js @@ -21,4 +21,4 @@ function stringToNumber (str){ return Number(str) } -stringToNumber("123"); \ No newline at end of file +stringToNumber("123"); From 559845ee5409b6fa25715134102ee2cd64534535 Mon Sep 17 00:00:00 2001 From: Liubomyr Halamaha Date: Thu, 16 May 2019 18:10:58 +0300 Subject: [PATCH 09/21] add requirejs --- main.js | 3 +++ package.json | 1 + tasks/template.js | 7 +++++++ 3 files changed, 11 insertions(+) create mode 100644 main.js create mode 100644 tasks/template.js diff --git a/main.js b/main.js new file mode 100644 index 0000000..c4c03e6 --- /dev/null +++ b/main.js @@ -0,0 +1,3 @@ +require("amd-loader"); +var msg = require('./tasks/template'); +msg.print("run!"); diff --git a/package.json b/package.json index f678785..085b793 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "description": "", "main": "index.js", "dependencies": { + "amd-loader": "0.0.8", "requirejs": "^2.3.6" }, "devDependencies": { diff --git a/tasks/template.js b/tasks/template.js new file mode 100644 index 0000000..4d24ed8 --- /dev/null +++ b/tasks/template.js @@ -0,0 +1,7 @@ +define(function () { + return { + print: function(msg) { + console.log(msg); + } + }; +}); \ No newline at end of file From 4ee462e9aa94e33ba008b89d958ac364cb077c49 Mon Sep 17 00:00:00 2001 From: MaxVoloskiy Date: Wed, 15 May 2019 22:15:20 +0300 Subject: [PATCH 10/21] added functions --- .gitignore | 3 +++ tasks/5_kyu.js | 16 ++++++++++++++++ tasks/6_kyu.js | 21 +++++++++++++++++++++ tasks/7_kyu.js | 7 +++++++ tasks/8_kyu.js | 20 ++++++++++++++++++++ 5 files changed, 67 insertions(+) diff --git a/.gitignore b/.gitignore index 9972163..0e26ec7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +# idea +.idea + # Logs logs *.log diff --git a/tasks/5_kyu.js b/tasks/5_kyu.js index e69de29..66b11a4 100644 --- a/tasks/5_kyu.js +++ b/tasks/5_kyu.js @@ -0,0 +1,16 @@ +function perimeter(n) { + return 4 * fibonacci(n); +} + +function fibonacci(n) { + + let init = 1; + let res = 1; + + for (let i = 0; i <= n; i++) { + let temp = res; + res += init; + init = temp; + } + return res - 1; +} diff --git a/tasks/6_kyu.js b/tasks/6_kyu.js index e69de29..93d3351 100644 --- a/tasks/6_kyu.js +++ b/tasks/6_kyu.js @@ -0,0 +1,21 @@ +function stockList(listOfArt, listOfCat) { + + if (!listOfArt.length || !listOfCat.length) { + return ''; + } + + let books = {}; + let result = []; + + listOfArt.forEach((book) => { + let [title, num] = book.split(" "); + books[title[0]] = books[title[0]] ? (books[title[0]] += Number(num)) : Number(num); + }); + + listOfCat.forEach((letter) => { + let num = books[letter] || 0; + result.push(`(${letter} : ${num})`); + }); + + return result.join` - `; +} \ No newline at end of file diff --git a/tasks/7_kyu.js b/tasks/7_kyu.js index e69de29..f797559 100644 --- a/tasks/7_kyu.js +++ b/tasks/7_kyu.js @@ -0,0 +1,7 @@ +function lockerRun(lockers){ + let open = []; + for (let i = 1; i * i <= lockers; i++) { + open.push(i * i); + } + return open; +} \ No newline at end of file diff --git a/tasks/8_kyu.js b/tasks/8_kyu.js index e69de29..96086b8 100644 --- a/tasks/8_kyu.js +++ b/tasks/8_kyu.js @@ -0,0 +1,20 @@ +function countPositivesSumNegatives(input) { + let positive = 0; + let negative = 0; + + if (input === [] || input === null || input < 1) + return []; + + for (let i=0; i 0){ + positive += 1; + } else { + negative += input[i] + } + } + return [positive, negative] +} + +function stringToNumber (str){ + return Number(str) +} \ No newline at end of file From 3141d216948cc726f6974b1b71b94a44d1b5ff3b Mon Sep 17 00:00:00 2001 From: MaxVoloskiy Date: Wed, 15 May 2019 22:28:50 +0300 Subject: [PATCH 11/21] added README --- README.md | 44 +++++++------------------------------------- 1 file changed, 7 insertions(+), 37 deletions(-) diff --git a/README.md b/README.md index c6f66a5..e39c4ce 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 | +| ------------- | ------------- | ------------- | +| Max Voloskiy | 8 | https://www.codewars.com/kata/count-of-positives-slash-sum-of-negatives | +| | 8 | https://www.codewars.com/kata/convert-a-string-to-a-number | +| | 7 | https://www.codewars.com/kata/slamming-lockers | +| | 6 | https://www.codewars.com/kata/help-the-bookseller | +| | 5 | https://www.codewars.com/kata/perimeter-of-squares-in-a-rectangle | \ No newline at end of file From 5d023256ecd714250dd85fcd96d6b9e7d79eb6a5 Mon Sep 17 00:00:00 2001 From: MaxVoloskiy Date: Wed, 15 May 2019 22:54:01 +0300 Subject: [PATCH 12/21] refactored files --- README.md | 2 +- tasks/6_kyu.js | 2 +- tasks/7_kyu.js | 2 +- tasks/8_kyu.js | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index e39c4ce..242633a 100644 --- a/README.md +++ b/README.md @@ -4,4 +4,4 @@ | | 8 | https://www.codewars.com/kata/convert-a-string-to-a-number | | | 7 | https://www.codewars.com/kata/slamming-lockers | | | 6 | https://www.codewars.com/kata/help-the-bookseller | -| | 5 | https://www.codewars.com/kata/perimeter-of-squares-in-a-rectangle | \ No newline at end of file +| | 5 | https://www.codewars.com/kata/perimeter-of-squares-in-a-rectangle | diff --git a/tasks/6_kyu.js b/tasks/6_kyu.js index 93d3351..c6831f4 100644 --- a/tasks/6_kyu.js +++ b/tasks/6_kyu.js @@ -18,4 +18,4 @@ function stockList(listOfArt, listOfCat) { }); return result.join` - `; -} \ No newline at end of file +} diff --git a/tasks/7_kyu.js b/tasks/7_kyu.js index f797559..b8a135d 100644 --- a/tasks/7_kyu.js +++ b/tasks/7_kyu.js @@ -4,4 +4,4 @@ function lockerRun(lockers){ open.push(i * i); } return open; -} \ No newline at end of file +} diff --git a/tasks/8_kyu.js b/tasks/8_kyu.js index 96086b8..9cf70f3 100644 --- a/tasks/8_kyu.js +++ b/tasks/8_kyu.js @@ -17,4 +17,4 @@ function countPositivesSumNegatives(input) { function stringToNumber (str){ return Number(str) -} \ No newline at end of file +} From 3c0a7cc9d3bb03f3a441b5be13ba008edaab9b28 Mon Sep 17 00:00:00 2001 From: MaxVoloskiy Date: Wed, 15 May 2019 22:15:20 +0300 Subject: [PATCH 13/21] added functions --- tasks/7_kyu.js | 2 +- tasks/8_kyu.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tasks/7_kyu.js b/tasks/7_kyu.js index b8a135d..2ae6c1d 100644 --- a/tasks/7_kyu.js +++ b/tasks/7_kyu.js @@ -1,4 +1,4 @@ -function lockerRun(lockers){ +function lockerRun(lockers) { let open = []; for (let i = 1; i * i <= lockers; i++) { open.push(i * i); diff --git a/tasks/8_kyu.js b/tasks/8_kyu.js index 9cf70f3..d884379 100644 --- a/tasks/8_kyu.js +++ b/tasks/8_kyu.js @@ -15,6 +15,6 @@ function countPositivesSumNegatives(input) { return [positive, negative] } -function stringToNumber (str){ +function stringToNumber (str) { return Number(str) } From 79965417d7e782e0280b0a74cde318c6c2729e51 Mon Sep 17 00:00:00 2001 From: MaxVoloskiy Date: Wed, 15 May 2019 22:28:50 +0300 Subject: [PATCH 14/21] added README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 242633a..e39c4ce 100644 --- a/README.md +++ b/README.md @@ -4,4 +4,4 @@ | | 8 | https://www.codewars.com/kata/convert-a-string-to-a-number | | | 7 | https://www.codewars.com/kata/slamming-lockers | | | 6 | https://www.codewars.com/kata/help-the-bookseller | -| | 5 | https://www.codewars.com/kata/perimeter-of-squares-in-a-rectangle | +| | 5 | https://www.codewars.com/kata/perimeter-of-squares-in-a-rectangle | \ No newline at end of file From fcbf2fd68f70df1ee41049134a852d4b34e99076 Mon Sep 17 00:00:00 2001 From: MaxVoloskiy Date: Wed, 15 May 2019 22:54:01 +0300 Subject: [PATCH 15/21] refactored files --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e39c4ce..242633a 100644 --- a/README.md +++ b/README.md @@ -4,4 +4,4 @@ | | 8 | https://www.codewars.com/kata/convert-a-string-to-a-number | | | 7 | https://www.codewars.com/kata/slamming-lockers | | | 6 | https://www.codewars.com/kata/help-the-bookseller | -| | 5 | https://www.codewars.com/kata/perimeter-of-squares-in-a-rectangle | \ No newline at end of file +| | 5 | https://www.codewars.com/kata/perimeter-of-squares-in-a-rectangle | From 3f88fec6b51b3a6ab813610dd2d55e3a4c93ed12 Mon Sep 17 00:00:00 2001 From: MaxVoloskiy Date: Thu, 16 May 2019 17:26:37 +0300 Subject: [PATCH 16/21] run functions --- tasks/5_kyu.js | 2 ++ tasks/6_kyu.js | 2 ++ tasks/7_kyu.js | 2 ++ tasks/8_kyu.js | 6 +++++- 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/tasks/5_kyu.js b/tasks/5_kyu.js index 66b11a4..3fb2a88 100644 --- a/tasks/5_kyu.js +++ b/tasks/5_kyu.js @@ -14,3 +14,5 @@ function fibonacci(n) { } return res - 1; } + +perimeter(10); \ No newline at end of file diff --git a/tasks/6_kyu.js b/tasks/6_kyu.js index c6831f4..b6d49c2 100644 --- a/tasks/6_kyu.js +++ b/tasks/6_kyu.js @@ -19,3 +19,5 @@ function stockList(listOfArt, listOfCat) { return result.join` - `; } + +stockList(["CBART 20", "CDXEF 50", "BKWRK 25", "BTSQZ 89", "DRTYM 60"], ["A", "B", "C", "W"]); \ No newline at end of file diff --git a/tasks/7_kyu.js b/tasks/7_kyu.js index 2ae6c1d..b6b8912 100644 --- a/tasks/7_kyu.js +++ b/tasks/7_kyu.js @@ -5,3 +5,5 @@ function lockerRun(lockers) { } return open; } + +lockerRun(9); \ No newline at end of file diff --git a/tasks/8_kyu.js b/tasks/8_kyu.js index d884379..02194c6 100644 --- a/tasks/8_kyu.js +++ b/tasks/8_kyu.js @@ -15,6 +15,10 @@ function countPositivesSumNegatives(input) { return [positive, negative] } -function stringToNumber (str) { +countPositivesSumNegatives([-1, -2, -3, 3, 2, 1]); + +function stringToNumber (str){ return Number(str) } + +stringToNumber("123"); \ No newline at end of file From f2cba2c5b24037aaa21bbb590e1fd8fe3d55126c Mon Sep 17 00:00:00 2001 From: MaxVoloskiy Date: Thu, 16 May 2019 17:40:48 +0300 Subject: [PATCH 17/21] added empty line --- tasks/5_kyu.js | 2 +- tasks/6_kyu.js | 2 +- tasks/7_kyu.js | 2 +- tasks/8_kyu.js | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tasks/5_kyu.js b/tasks/5_kyu.js index 3fb2a88..27834fd 100644 --- a/tasks/5_kyu.js +++ b/tasks/5_kyu.js @@ -15,4 +15,4 @@ function fibonacci(n) { return res - 1; } -perimeter(10); \ No newline at end of file +perimeter(10); diff --git a/tasks/6_kyu.js b/tasks/6_kyu.js index b6d49c2..341d0a4 100644 --- a/tasks/6_kyu.js +++ b/tasks/6_kyu.js @@ -20,4 +20,4 @@ function stockList(listOfArt, listOfCat) { return result.join` - `; } -stockList(["CBART 20", "CDXEF 50", "BKWRK 25", "BTSQZ 89", "DRTYM 60"], ["A", "B", "C", "W"]); \ No newline at end of file +stockList(["CBART 20", "CDXEF 50", "BKWRK 25", "BTSQZ 89", "DRTYM 60"], ["A", "B", "C", "W"]); diff --git a/tasks/7_kyu.js b/tasks/7_kyu.js index b6b8912..3b6f2f4 100644 --- a/tasks/7_kyu.js +++ b/tasks/7_kyu.js @@ -6,4 +6,4 @@ function lockerRun(lockers) { return open; } -lockerRun(9); \ No newline at end of file +lockerRun(9); diff --git a/tasks/8_kyu.js b/tasks/8_kyu.js index 02194c6..62f87ab 100644 --- a/tasks/8_kyu.js +++ b/tasks/8_kyu.js @@ -21,4 +21,4 @@ function stringToNumber (str){ return Number(str) } -stringToNumber("123"); \ No newline at end of file +stringToNumber("123"); From 9635832bfd2ffd9761b7a2105c96e4ddb797431d Mon Sep 17 00:00:00 2001 From: MaxVoloskiy Date: Thu, 16 May 2019 23:56:59 +0300 Subject: [PATCH 18/21] refactored files --- index.js | 16 +++++++++++++++- tasks/5_kyu.js | 33 +++++++++++++++++---------------- tasks/6_kyu.js | 39 ++++++++++++++++++++------------------- tasks/7_kyu.js | 18 ++++++++++-------- tasks/8_kyu.js | 39 +++++++++++++++++++-------------------- 5 files changed, 81 insertions(+), 64 deletions(-) diff --git a/index.js b/index.js index 4835cad..94117f4 100644 --- a/index.js +++ b/index.js @@ -1 +1,15 @@ -var requirejs = require('tasks/5_kyu'); \ No newline at end of file +require("amd-loader"); + +let fifth = require('./tasks/5_kyu'); +console.log(fifth.perimeter(10)); + +let sixth = require('./tasks/6_kyu'); +console.log(sixth.stockList(["CBART 20", "CDXEF 50", "BKWRK 25", "BTSQZ 89", "DRTYM 60"], ["A", "B", "C", "W"])); + +let seventh = require('./tasks/7_kyu'); +console.log(seventh.lockerRun(9)); + +let eighth = require('./tasks/8_kyu'); +console.log(eighth.stringToNumber("123")); +console.log(eighth.countPositivesSumNegatives([-1, -2, -3, 1, 2, 3])); + diff --git a/tasks/5_kyu.js b/tasks/5_kyu.js index 27834fd..837063e 100644 --- a/tasks/5_kyu.js +++ b/tasks/5_kyu.js @@ -1,18 +1,19 @@ -function perimeter(n) { - return 4 * fibonacci(n); -} +define(function () { + return { + perimeter: (n) => { + const fibonacci = (n) => { + let init = 1; + let res = 1; -function fibonacci(n) { + for (let i = 0; i <= n; i++) { + let temp = res; + res += init; + init = temp; + } + return res - 1; + }; - let init = 1; - let res = 1; - - for (let i = 0; i <= n; i++) { - let temp = res; - res += init; - init = temp; - } - return res - 1; -} - -perimeter(10); + return 4 * fibonacci(n); + } + }; +}); diff --git a/tasks/6_kyu.js b/tasks/6_kyu.js index 341d0a4..f6b99f5 100644 --- a/tasks/6_kyu.js +++ b/tasks/6_kyu.js @@ -1,23 +1,24 @@ -function stockList(listOfArt, listOfCat) { +define(function () { + return { + stockList: (listOfArt, listOfCat) => { + if (!listOfArt.length || !listOfCat.length) { + return ''; + } - if (!listOfArt.length || !listOfCat.length) { - return ''; - } - - let books = {}; - let result = []; + let books = {}; + let result = []; - listOfArt.forEach((book) => { - let [title, num] = book.split(" "); - books[title[0]] = books[title[0]] ? (books[title[0]] += Number(num)) : Number(num); - }); + listOfArt.forEach((book) => { + let [title, num] = book.split(" "); + books[title[0]] = books[title[0]] ? (books[title[0]] += Number(num)) : Number(num); + }); - listOfCat.forEach((letter) => { - let num = books[letter] || 0; - result.push(`(${letter} : ${num})`); - }); + listOfCat.forEach((letter) => { + let num = books[letter] || 0; + result.push(`(${letter} : ${num})`); + }); - return result.join` - `; -} - -stockList(["CBART 20", "CDXEF 50", "BKWRK 25", "BTSQZ 89", "DRTYM 60"], ["A", "B", "C", "W"]); + return result.join` - `; + } + } +}); diff --git a/tasks/7_kyu.js b/tasks/7_kyu.js index 3b6f2f4..5e34750 100644 --- a/tasks/7_kyu.js +++ b/tasks/7_kyu.js @@ -1,9 +1,11 @@ -function lockerRun(lockers) { - let open = []; - for (let i = 1; i * i <= lockers; i++) { - open.push(i * i); +define(function () { + return { + lockerRun: (lockers) => { + let open = []; + for (let i = 1; i * i <= lockers; i++) { + open.push(i * i); + } + return open; + } } - return open; -} - -lockerRun(9); +}); diff --git a/tasks/8_kyu.js b/tasks/8_kyu.js index 62f87ab..dab7300 100644 --- a/tasks/8_kyu.js +++ b/tasks/8_kyu.js @@ -1,24 +1,23 @@ -function countPositivesSumNegatives(input) { - let positive = 0; - let negative = 0; +define(function () { + return { + countPositivesSumNegatives: (input) => { + let positive = 0; + let negative = 0; - if (input === [] || input === null || input < 1) - return []; + if (input === [] || input === null || input < 1) + return []; - for (let i=0; i 0){ - positive += 1; - } else { - negative += input[i] + for (let i=0; i 0){ + positive += 1; + } else { + negative += input[i] + } + } + return [positive, negative] + }, + stringToNumber: (n) => { + return Number(n); } } - return [positive, negative] -} - -countPositivesSumNegatives([-1, -2, -3, 3, 2, 1]); - -function stringToNumber (str){ - return Number(str) -} - -stringToNumber("123"); +}); From ae406ce5eb3737c7093970110b92f36f85d82ea3 Mon Sep 17 00:00:00 2001 From: MaxVoloskiy Date: Fri, 17 May 2019 00:02:51 +0300 Subject: [PATCH 19/21] changed travis --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index bd9b16f..c8c0cf1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,5 @@ +language: node_js + install: - nvm install stable - npm install -g eslint-cli From bd3e1c396b38196479304eabe60cc29d1514d4b6 Mon Sep 17 00:00:00 2001 From: MaxVoloskiy Date: Fri, 17 May 2019 00:08:03 +0300 Subject: [PATCH 20/21] refactored example and rewrited eslint --- .eslintrc.js | 3 ++- .travis.yml | 2 -- main.js | 2 +- tasks/template.js | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) 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/.travis.yml b/.travis.yml index c8c0cf1..bd9b16f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,3 @@ -language: node_js - install: - nvm install stable - npm install -g eslint-cli diff --git a/main.js b/main.js index c4c03e6..a0c5cfd 100644 --- a/main.js +++ b/main.js @@ -1,3 +1,3 @@ require("amd-loader"); var msg = require('./tasks/template'); -msg.print("run!"); +console.log(msg.print("run!")); diff --git a/tasks/template.js b/tasks/template.js index 4d24ed8..ec0a7a7 100644 --- a/tasks/template.js +++ b/tasks/template.js @@ -1,7 +1,7 @@ define(function () { return { print: function(msg) { - console.log(msg); + return msg; } }; }); \ No newline at end of file From c42348d3d60a4627b5e137e4577df485f644ae30 Mon Sep 17 00:00:00 2001 From: MaxVoloskiy Date: Fri, 17 May 2019 00:10:00 +0300 Subject: [PATCH 21/21] changed travis --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index bd9b16f..c8c0cf1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,5 @@ +language: node_js + install: - nvm install stable - npm install -g eslint-cli