From 7441dde2d5822304d948d08dca97edca67770cbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=BE=D0=BC=D1=8C=D1=8F=D0=BD=D0=B8=D1=87=20=D0=90?= =?UTF-8?q?=D0=BB=D0=B5=D0=BA=D1=81=D0=B5=D0=B9?= Date: Thu, 16 May 2019 23:41:39 +0300 Subject: [PATCH 1/4] changed code --- main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.js b/main.js index c4c03e6..0305b51 100644 --- a/main.js +++ b/main.js @@ -1,3 +1,3 @@ require("amd-loader"); var msg = require('./tasks/template'); -msg.print("run!"); +msg.print("run!"); \ No newline at end of file From e6595274dbc79eba6533d8dc07965438fdd72719 Mon Sep 17 00:00:00 2001 From: GeFeST Date: Wed, 15 May 2019 22:47:41 +0300 Subject: [PATCH 2/4] add files to my branch add empty line in the end of task updated with console.log add requirejs add require changed main.js fix eslintrc fix template --- .eslintrc.js | 3 ++- README.md | 44 +++++++------------------------------------- main.js | 20 ++++++++++++++++++-- tasks/5_kyu.js | 21 +++++++++++++++++++++ tasks/6_kyu.js | 42 ++++++++++++++++++++++++++++++++++++++++++ tasks/7_kyu.js | 11 +++++++++++ tasks/8_kyu.js | 14 ++++++++++++++ 7 files changed, 115 insertions(+), 40 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/README.md b/README.md index c6f66a5..ec5e0c0 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 | +| ------------- | ------------- | ------------- | +| Oleksii Domianych | 8 |https://www.codewars.com/kata/wilson-primes | +| | 8 | https://www.codewars.com/kata/formatting-decimal-places-number-0 | +| | 7 | https://www.codewars.com/kata/looking-for-a-benefactor | +| | 6 | https://www.codewars.com/kata/easy-balance-checking | +| | 5 | https://www.codewars.com/kata/find-the-smallest | \ No newline at end of file diff --git a/main.js b/main.js index 0305b51..b7404fc 100644 --- a/main.js +++ b/main.js @@ -1,3 +1,19 @@ require("amd-loader"); -var msg = require('./tasks/template'); -msg.print("run!"); \ No newline at end of file + +const kyu_8 = require('./tasks/8_kyu'); +console.log(kyu_8.amIWilson(5)); +console.log(kyu_8.twoDecimalPlaces(4.659725356)); + +const kyu_7 = require('./tasks/7_kyu'); +console.log(kyu_7.newAvg([14, 30, 5, 7, 9, 11, 16], 90)); + +const kyu_6 = require('./tasks/6_kyu'); +console.log(kyu_6.balance(`1000.00 +125 Market 125.45 +126 Hardware 34.95 +127 Video 7.45 +128 Book 14.32 +129 Gasoline 16.10`)); + +const kyu_5 = require('./tasks/5_kyu'); +console.log(kyu_5.smallest(25825)); diff --git a/tasks/5_kyu.js b/tasks/5_kyu.js index e69de29..7495245 100644 --- a/tasks/5_kyu.js +++ b/tasks/5_kyu.js @@ -0,0 +1,21 @@ +define(function () { + return { + smallest: function (n) { + let row = String(n).split(""); + let min = [n, 0, 0]; + let test = []; + + for (let i = 0, length = row.length; i < length; i++) { + for (let j = 0; j < length; j++) { + test = row.slice(0, i).concat(row.slice(i + 1)); + + if (Number(test.slice(0, j).concat(row[i], test.slice(j)).join("")) < min[0]) { + min = [Number(test.slice(0, j).concat(row[i], test.slice(j)).join("")), i, j]; + } + } + } + + return min; + } + }; +}); diff --git a/tasks/6_kyu.js b/tasks/6_kyu.js index e69de29..56e015b 100644 --- a/tasks/6_kyu.js +++ b/tasks/6_kyu.js @@ -0,0 +1,42 @@ +define(function () { + return { + balance: function (book) { + let arrBook = bookToArray(book); + + arrBook[0][0] = numberFormat(arrBook[0][0], 2); //lead to a numeric format with 2 digits after comma + let balance = parseFloat(arrBook[0][0]); + let sumForAvg = 0; + + for (let i = 1; i < arrBook.length; i++) { + arrBook[i][1] = arrBook[i][1].replace(/\W/g, ''); //replace everything except letters + arrBook[i][2] = numberFormat(arrBook[i][2], 2); + balance -= +arrBook[i][2]; + sumForAvg += +arrBook[i][2]; + arrBook[i].push('Balance ' + balance.toFixed(2)); + } + + arrBook.push( + [`Total expense ${(+arrBook[0][0] - balance).toFixed(2)}`], [`Average expense ${(sumForAvg / (arrBook.length - 1)).toFixed(2)}`] + ); + arrBook[0][0] = 'Original Balance: ' + arrBook[0][0]; + + return bookToString(arrBook); + + function bookToString(array) { + return array.map(e => e.join(' ')).join('\r\n'); + } + + function bookToArray(book) { + return book.split('\n') + .map(e => e.split(' ')) + .filter(e => e.toString() !== ''); + } + + function numberFormat(str, cur = 2) { + str = str.replace(/[^\d+.]/g, ''); + str = (+str).toFixed(cur); + return str; + } + } + }; +}); diff --git a/tasks/7_kyu.js b/tasks/7_kyu.js index e69de29..7ada8bd 100644 --- a/tasks/7_kyu.js +++ b/tasks/7_kyu.js @@ -0,0 +1,11 @@ +define(function () { + return { + newAvg: function (arr, newavg) { + let totalSum = arr.reduce((total, current) => total + current, 0); + let result = newavg * (arr.length + 1) - totalSum; + + if (result < 0) throw new RangeError('Error') + return Math.ceil(result) + } + }; +}); diff --git a/tasks/8_kyu.js b/tasks/8_kyu.js index e69de29..b57847c 100644 --- a/tasks/8_kyu.js +++ b/tasks/8_kyu.js @@ -0,0 +1,14 @@ +define(function () { + return { + amIWilson: function (p) { + function fact(x) { + return x <= 1 ? 1 : x * fact(x - 1); + } + + return (fact(p - 1) + 1) / (p * p) % 1 === 0; + }, + twoDecimalPlaces: function (n) { + return +n.toFixed(2) + } + }; +}); From 077e3b26e61bdf62ca3442ee9449cff9942ec98f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=BE=D0=BC=D1=8C=D1=8F=D0=BD=D0=B8=D1=87=20=D0=90?= =?UTF-8?q?=D0=BB=D0=B5=D0=BA=D1=81=D0=B5=D0=B9?= Date: Fri, 17 May 2019 17:03:48 +0300 Subject: [PATCH 3/4] change template --- tasks/template.js | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tasks/template.js b/tasks/template.js index 4d24ed8..e69de29 100644 --- a/tasks/template.js +++ b/tasks/template.js @@ -1,7 +0,0 @@ -define(function () { - return { - print: function(msg) { - console.log(msg); - } - }; -}); \ No newline at end of file From 7eee7f3bd94406dcfb4b3f580a1583c73b867ee2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=BE=D0=BC=D1=8C=D1=8F=D0=BD=D0=B8=D1=87=20=D0=90?= =?UTF-8?q?=D0=BB=D0=B5=D0=BA=D1=81=D0=B5=D0=B9?= Date: Thu, 30 May 2019 19:01:47 +0300 Subject: [PATCH 4/4] change kyu6 --- tasks/6_kyu.js | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/tasks/6_kyu.js b/tasks/6_kyu.js index 56e015b..4df5818 100644 --- a/tasks/6_kyu.js +++ b/tasks/6_kyu.js @@ -1,7 +1,15 @@ define(function () { return { balance: function (book) { - let arrBook = bookToArray(book); + const numberFormat = function(str, cur = 2) { + str = str.replace(/[^\d+.]/g, ''); + str = (+str).toFixed(cur); + return str; + } + + let arrBook = book.split('\n') + .map(e => e.split(' ')) + .filter(e => e.toString() !== '');; arrBook[0][0] = numberFormat(arrBook[0][0], 2); //lead to a numeric format with 2 digits after comma let balance = parseFloat(arrBook[0][0]); @@ -20,23 +28,7 @@ define(function () { ); arrBook[0][0] = 'Original Balance: ' + arrBook[0][0]; - return bookToString(arrBook); - - function bookToString(array) { - return array.map(e => e.join(' ')).join('\r\n'); - } - - function bookToArray(book) { - return book.split('\n') - .map(e => e.split(' ')) - .filter(e => e.toString() !== ''); - } - - function numberFormat(str, cur = 2) { - str = str.replace(/[^\d+.]/g, ''); - str = (+str).toFixed(cur); - return str; - } + return arrBook.map(e => e.join(' ')).join('\r\n'); } }; });