Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
module.exports = {
"env": {
"browser": true,
"es6": true
"es6": true,
"amd": true
},
"extends": "eslint:recommended",
"globals": {
Expand Down
44 changes: 7 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
@@ -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 |
20 changes: 18 additions & 2 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
require("amd-loader");
var msg = require('./tasks/template');
msg.print("run!");

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));
21 changes: 21 additions & 0 deletions tasks/5_kyu.js
Original file line number Diff line number Diff line change
@@ -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;
}
};
});
34 changes: 34 additions & 0 deletions tasks/6_kyu.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
define(function () {
return {
balance: function (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]);
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 arrBook.map(e => e.join(' ')).join('\r\n');
}
};
});
11 changes: 11 additions & 0 deletions tasks/7_kyu.js
Original file line number Diff line number Diff line change
@@ -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)
}
};
});
14 changes: 14 additions & 0 deletions tasks/8_kyu.js
Original file line number Diff line number Diff line change
@@ -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)
}
};
});
7 changes: 0 additions & 7 deletions tasks/template.js
Original file line number Diff line number Diff line change
@@ -1,7 +0,0 @@
define(function () {
return {
print: function(msg) {
console.log(msg);
}
};
});