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/.gitignore b/.gitignore index 9972163..0e26ec7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +# idea +.idea + # Logs logs *.log 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 diff --git a/README.md b/README.md index c6f66a5..242633a 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 | 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/main.js b/main.js new file mode 100644 index 0000000..a0c5cfd --- /dev/null +++ b/main.js @@ -0,0 +1,3 @@ +require("amd-loader"); +var msg = require('./tasks/template'); +console.log(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/5_kyu.js b/tasks/5_kyu.js index e69de29..837063e 100644 --- a/tasks/5_kyu.js +++ b/tasks/5_kyu.js @@ -0,0 +1,19 @@ +define(function () { + return { + perimeter: (n) => { + const 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; + }; + + return 4 * fibonacci(n); + } + }; +}); diff --git a/tasks/6_kyu.js b/tasks/6_kyu.js index e69de29..f6b99f5 100644 --- a/tasks/6_kyu.js +++ b/tasks/6_kyu.js @@ -0,0 +1,24 @@ +define(function () { + return { + 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` - `; + } + } +}); diff --git a/tasks/7_kyu.js b/tasks/7_kyu.js index e69de29..5e34750 100644 --- a/tasks/7_kyu.js +++ b/tasks/7_kyu.js @@ -0,0 +1,11 @@ +define(function () { + return { + lockerRun: (lockers) => { + let open = []; + for (let i = 1; i * i <= lockers; i++) { + open.push(i * i); + } + return open; + } + } +}); diff --git a/tasks/8_kyu.js b/tasks/8_kyu.js index e69de29..dab7300 100644 --- a/tasks/8_kyu.js +++ b/tasks/8_kyu.js @@ -0,0 +1,23 @@ +define(function () { + return { + 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] + }, + stringToNumber: (n) => { + return Number(n); + } + } +}); diff --git a/tasks/template.js b/tasks/template.js new file mode 100644 index 0000000..ec0a7a7 --- /dev/null +++ b/tasks/template.js @@ -0,0 +1,7 @@ +define(function () { + return { + print: function(msg) { + return msg; + } + }; +}); \ No newline at end of file