From ee637aa69469ec3cfed406330bbee7c9f9f88d77 Mon Sep 17 00:00:00 2001 From: Nadiia Chorna Date: Tue, 28 May 2019 18:07:33 +0300 Subject: [PATCH 01/17] add tasks solutions --- README.md | 8 ++++++++ tasks/5_kyu.js | 9 +++++++++ tasks/7_kyu.js | 3 +++ tasks/8_kyu.js | 14 ++++++++++++++ 4 files changed, 34 insertions(+) diff --git a/README.md b/README.md index c6f66a5..b521fef 100644 --- a/README.md +++ b/README.md @@ -35,3 +35,11 @@ Your Pages site will use the layout and styles from the Jekyll theme you have se ### 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 | +| ------------- | ------------- | ------------- | +| Nadiia Chorna | 8 |https://www.codewars.com/kata/my-head-is-at-the-wrong-end | +| | 8 | https://www.codewars.com/kata/to-square-root-or-not-to-square-root | +| | 7 | https://www.codewars.com/kata/recursive-replication | +| | 6 | https://www.codewars.com/kata/ranking-nba-teams | +| | 5 | https://www.codewars.com/kata/number-of-trailing-zeros-of-n | diff --git a/tasks/5_kyu.js b/tasks/5_kyu.js index e69de29..f574559 100644 --- a/tasks/5_kyu.js +++ b/tasks/5_kyu.js @@ -0,0 +1,9 @@ +function zeros (n) { + var i = 1; + var result = 0; + while(n/Math.pow(5,i)>1){ + result += Math.floor(n/Math.pow(5,i)); + i++; + } + return result; +} diff --git a/tasks/7_kyu.js b/tasks/7_kyu.js index e69de29..d5a6dc9 100644 --- a/tasks/7_kyu.js +++ b/tasks/7_kyu.js @@ -0,0 +1,3 @@ +function replicate(times, number) { + return times>0 ? [number].concat(replicate(times-1, number)) : []; +} \ No newline at end of file diff --git a/tasks/8_kyu.js b/tasks/8_kyu.js index e69de29..2b10640 100644 --- a/tasks/8_kyu.js +++ b/tasks/8_kyu.js @@ -0,0 +1,14 @@ + +// -------------- 1 ---------------- + +function fixTheMeerkat(arr) { + return arr.reverse(); +} + +// -------------- 2 ---------------- + +function squareOrSquareRoot(arr) { + return array.map((el)=>{ + return Number.isInteger(Math.sqrt(el)) ? Math.sqrt(el) : Math.pow(el,2); + }) +} \ No newline at end of file From 853eb66fd0396d4ebcb54ff74f0e5179b52f4245 Mon Sep 17 00:00:00 2001 From: Nadiia Chorna Date: Tue, 28 May 2019 19:44:27 +0300 Subject: [PATCH 02/17] add "define" function --- tasks/5_kyu.js | 20 ++++++++++++-------- tasks/7_kyu.js | 10 +++++++--- tasks/8_kyu.js | 24 ++++++++++++++++-------- 3 files changed, 35 insertions(+), 19 deletions(-) diff --git a/tasks/5_kyu.js b/tasks/5_kyu.js index f574559..cebe0bb 100644 --- a/tasks/5_kyu.js +++ b/tasks/5_kyu.js @@ -1,9 +1,13 @@ -function zeros (n) { - var i = 1; - var result = 0; - while(n/Math.pow(5,i)>1){ - result += Math.floor(n/Math.pow(5,i)); - i++; +define(function(){ + return { + zeros: function (n) { + var i = 1; + var result = 0; + while(n/Math.pow(5,i)>1){ + result += Math.floor(n/Math.pow(5,i)); + i++; + } + return result; } - return result; -} + } +}); \ No newline at end of file diff --git a/tasks/7_kyu.js b/tasks/7_kyu.js index d5a6dc9..d3bc14f 100644 --- a/tasks/7_kyu.js +++ b/tasks/7_kyu.js @@ -1,3 +1,7 @@ -function replicate(times, number) { - return times>0 ? [number].concat(replicate(times-1, number)) : []; -} \ No newline at end of file +define(function(){ + return { + replicate: function(times, number) { + return times>0 ? [number].concat(replicate(times-1, number)) : []; + } + } +}); \ No newline at end of file diff --git a/tasks/8_kyu.js b/tasks/8_kyu.js index 2b10640..0b2a58a 100644 --- a/tasks/8_kyu.js +++ b/tasks/8_kyu.js @@ -1,14 +1,22 @@ // -------------- 1 ---------------- -function fixTheMeerkat(arr) { - return arr.reverse(); -} +define(function(){ + return { + fixTheMeerkat: function(arr) { + return arr.reverse(); + } + } +}); // -------------- 2 ---------------- -function squareOrSquareRoot(arr) { - return array.map((el)=>{ - return Number.isInteger(Math.sqrt(el)) ? Math.sqrt(el) : Math.pow(el,2); - }) -} \ No newline at end of file +define(function(){ + return { + squareOrSquareRoot: function(arr) { + return array.map((el)=>{ + return Number.isInteger(Math.sqrt(el)) ? Math.sqrt(el) : Math.pow(el,2); + }) + } + } +}); \ No newline at end of file From e7244f3ed01b84d0cf8ed6d98e575e40a3a3ff2d Mon Sep 17 00:00:00 2001 From: Nadiia Chorna Date: Tue, 28 May 2019 23:47:26 +0300 Subject: [PATCH 03/17] error resolved --- .eslintrc.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.eslintrc.js b/.eslintrc.js index edadc67..2b2e3a4 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": { From 00e0a7224ef2c982aea6192c2e930dfec9fa7935 Mon Sep 17 00:00:00 2001 From: Nadiia Chorna Date: Tue, 28 May 2019 23:50:40 +0300 Subject: [PATCH 04/17] error resolvig --- .eslintrc.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.eslintrc.js b/.eslintrc.js index 2b2e3a4..d969a52 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,7 +1,7 @@ module.exports = { "env": { "browser": true, - "es6": trueб + "es6": true, "amd": true }, "extends": "eslint:recommended", From 35c45e85b30dcb4cd97eaf823ca1aedbde7adc4e Mon Sep 17 00:00:00 2001 From: Nadiia Chorna Date: Wed, 29 May 2019 00:13:38 +0300 Subject: [PATCH 05/17] changed main.js --- main.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/main.js b/main.js index c4c03e6..70104ad 100644 --- a/main.js +++ b/main.js @@ -1,3 +1,15 @@ require("amd-loader"); -var msg = require('./tasks/template'); -msg.print("run!"); +//var msg = require('./tasks/template'); +//msg.print("run!"); + +var kyu8=require('./tasks/8_kyu'); +console.log(kyu8.fixTheMeerkat(['tail', 'body', 'head'])); +console.log(kyu8.squareOrSquareRoot([4,3,9,7,2,1])); + +var kyu7=require('./tasks/7_kyu'); +console.log(kyu7.replicate(3,5)); + +//var kyu6=require('./tasks/6_kyu'); + +var kyu5=require('./tasks/5_kyu'); +console.log(kyu5.zeros(6)); \ No newline at end of file From d637dc0f354884525fe154b114747bf5e81ddd6d Mon Sep 17 00:00:00 2001 From: Nadiia Chorna Date: Wed, 29 May 2019 00:24:27 +0300 Subject: [PATCH 06/17] changed param name --- tasks/6_kyu.js | 14 ++++++++++++++ tasks/8_kyu.js | 2 +- tasks/template.js | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/tasks/6_kyu.js b/tasks/6_kyu.js index e69de29..b09b7a6 100644 --- a/tasks/6_kyu.js +++ b/tasks/6_kyu.js @@ -0,0 +1,14 @@ +r = 'Los Angeles Clippers 104 Dallas Mavericks 88,New York Knicks 101 Atlanta Hawks 112,Indiana Pacers 103 Memphis Grizzlies 112, Los Angeles Clippers 100 Boston Celtics 120'; + +function nba_cup(str, team){ +let w, d, l, scored, conceded, points; + +let arr = str.split(',') +.map((item)=>{ +return item.match(/([a-zA-Z\s]+)([0-9]+)/ig); +}) + +console.log(arr); +} + +nba_cup(r); \ No newline at end of file diff --git a/tasks/8_kyu.js b/tasks/8_kyu.js index 0b2a58a..251cae0 100644 --- a/tasks/8_kyu.js +++ b/tasks/8_kyu.js @@ -14,7 +14,7 @@ define(function(){ define(function(){ return { squareOrSquareRoot: function(arr) { - return array.map((el)=>{ + return arr.map((el)=>{ return Number.isInteger(Math.sqrt(el)) ? Math.sqrt(el) : Math.pow(el,2); }) } diff --git a/tasks/template.js b/tasks/template.js index 4d24ed8..3fd126d 100644 --- a/tasks/template.js +++ b/tasks/template.js @@ -1,7 +1,7 @@ define(function () { return { print: function(msg) { - console.log(msg); + // console.log(msg); } }; }); \ No newline at end of file From 1ea22e68ccbdb0cd621d750715d045fd03d7b6fb Mon Sep 17 00:00:00 2001 From: Nadiia Chorna Date: Wed, 29 May 2019 00:27:34 +0300 Subject: [PATCH 07/17] changed package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 085b793..a75234d 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "codewarstasks", "version": "1.0.0", "description": "", - "main": "index.js", + "main": "main.js", "dependencies": { "amd-loader": "0.0.8", "requirejs": "^2.3.6" From a4e8622948eed53ecec55c5ba46f44e1802332da Mon Sep 17 00:00:00 2001 From: Nadiia Chorna Date: Wed, 29 May 2019 00:29:33 +0300 Subject: [PATCH 08/17] changed task 6_kyu --- tasks/6_kyu.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tasks/6_kyu.js b/tasks/6_kyu.js index b09b7a6..1169b3c 100644 --- a/tasks/6_kyu.js +++ b/tasks/6_kyu.js @@ -1,14 +1,14 @@ -r = 'Los Angeles Clippers 104 Dallas Mavericks 88,New York Knicks 101 Atlanta Hawks 112,Indiana Pacers 103 Memphis Grizzlies 112, Los Angeles Clippers 100 Boston Celtics 120'; +// r = 'Los Angeles Clippers 104 Dallas Mavericks 88,New York Knicks 101 Atlanta Hawks 112,Indiana Pacers 103 Memphis Grizzlies 112, Los Angeles Clippers 100 Boston Celtics 120'; -function nba_cup(str, team){ -let w, d, l, scored, conceded, points; +// function nba_cup(str, team){ +// let w, d, l, scored, conceded, points; -let arr = str.split(',') -.map((item)=>{ -return item.match(/([a-zA-Z\s]+)([0-9]+)/ig); -}) +// let arr = str.split(',') +// .map((item)=>{ +// return item.match(/([a-zA-Z\s]+)([0-9]+)/ig); +// }) -console.log(arr); -} +// console.log(arr); +// } -nba_cup(r); \ No newline at end of file +// nba_cup(r); \ No newline at end of file From 935a9d7dc6ee30b0199ef6416aa80a3c8e2e70e7 Mon Sep 17 00:00:00 2001 From: Nadiia Chorna Date: Wed, 29 May 2019 10:12:26 +0300 Subject: [PATCH 09/17] fixed mixed-spaces-and-tabs err --- .eslintrc.js | 3 +-- package.json | 2 +- tasks/5_kyu.js | 14 +++++++------- tasks/7_kyu.js | 4 ++-- tasks/8_kyu.js | 11 +++++------ tasks/template.js | 12 ++++++------ 6 files changed, 22 insertions(+), 24 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index d969a52..a8ea689 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -13,6 +13,5 @@ module.exports = { "ecmaVersion": 2018, "sourceType": "module" }, - "rules": { - } + "rules": {} }; \ No newline at end of file diff --git a/package.json b/package.json index a75234d..c4ef32b 100644 --- a/package.json +++ b/package.json @@ -24,4 +24,4 @@ "url": "https://github.com/lv-411-nodejs/codeWarsTasks/issues" }, "homepage": "https://github.com/lv-411-nodejs/codeWarsTasks#readme" -} +} \ No newline at end of file diff --git a/tasks/5_kyu.js b/tasks/5_kyu.js index cebe0bb..ccc9875 100644 --- a/tasks/5_kyu.js +++ b/tasks/5_kyu.js @@ -1,12 +1,12 @@ -define(function(){ +define(function() { return { - zeros: function (n) { - var i = 1; + zeros: function(n) { + var i = 1; var result = 0; - while(n/Math.pow(5,i)>1){ - result += Math.floor(n/Math.pow(5,i)); - i++; - } + while (n / Math.pow(5, i) > 1) { + result += Math.floor(n / Math.pow(5, i)); + i++; + } return result; } } diff --git a/tasks/7_kyu.js b/tasks/7_kyu.js index d3bc14f..0722857 100644 --- a/tasks/7_kyu.js +++ b/tasks/7_kyu.js @@ -1,7 +1,7 @@ -define(function(){ +define(function() { return { replicate: function(times, number) { - return times>0 ? [number].concat(replicate(times-1, number)) : []; + return times > 0 ? [number].concat(replicate(times - 1, number)) : []; } } }); \ No newline at end of file diff --git a/tasks/8_kyu.js b/tasks/8_kyu.js index 251cae0..a06a815 100644 --- a/tasks/8_kyu.js +++ b/tasks/8_kyu.js @@ -1,21 +1,20 @@ - // -------------- 1 ---------------- -define(function(){ +define(function() { return { fixTheMeerkat: function(arr) { - return arr.reverse(); + return arr.reverse(); } } }); // -------------- 2 ---------------- -define(function(){ +define(function() { return { squareOrSquareRoot: function(arr) { - return arr.map((el)=>{ - return Number.isInteger(Math.sqrt(el)) ? Math.sqrt(el) : Math.pow(el,2); + return arr.map((el) => { + return Number.isInteger(Math.sqrt(el)) ? Math.sqrt(el) : Math.pow(el, 2); }) } } diff --git a/tasks/template.js b/tasks/template.js index 3fd126d..3bc65d4 100644 --- a/tasks/template.js +++ b/tasks/template.js @@ -1,7 +1,7 @@ -define(function () { - return { - print: function(msg) { - // console.log(msg); - } - }; +define(function() { + return { + print: function(msg) { + // console.log(msg); + } + }; }); \ No newline at end of file From aa8e14c5f278cdbd456e6f7924459f20d125dddc Mon Sep 17 00:00:00 2001 From: Nadiia Chorna Date: Wed, 29 May 2019 10:35:41 +0300 Subject: [PATCH 10/17] add tabs --- main.js | 10 +++++----- tasks/5_kyu.js | 2 +- tasks/6_kyu.js | 2 +- tasks/7_kyu.js | 2 +- tasks/8_kyu.js | 2 +- tasks/template.js | 14 +++++++------- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/main.js b/main.js index 70104ad..2e91fe7 100644 --- a/main.js +++ b/main.js @@ -2,14 +2,14 @@ require("amd-loader"); //var msg = require('./tasks/template'); //msg.print("run!"); -var kyu8=require('./tasks/8_kyu'); +var kyu8 = require('./tasks/8_kyu'); console.log(kyu8.fixTheMeerkat(['tail', 'body', 'head'])); -console.log(kyu8.squareOrSquareRoot([4,3,9,7,2,1])); +console.log(kyu8.squareOrSquareRoot([4, 3, 9, 7, 2, 1])); -var kyu7=require('./tasks/7_kyu'); -console.log(kyu7.replicate(3,5)); +var kyu7 = require('./tasks/7_kyu'); +console.log(kyu7.replicate(3, 5)); //var kyu6=require('./tasks/6_kyu'); -var kyu5=require('./tasks/5_kyu'); +var kyu5 = require('./tasks/5_kyu'); console.log(kyu5.zeros(6)); \ No newline at end of file diff --git a/tasks/5_kyu.js b/tasks/5_kyu.js index ccc9875..fe31cad 100644 --- a/tasks/5_kyu.js +++ b/tasks/5_kyu.js @@ -10,4 +10,4 @@ define(function() { return result; } } -}); \ No newline at end of file +}); diff --git a/tasks/6_kyu.js b/tasks/6_kyu.js index 1169b3c..d3bef2f 100644 --- a/tasks/6_kyu.js +++ b/tasks/6_kyu.js @@ -11,4 +11,4 @@ // console.log(arr); // } -// nba_cup(r); \ No newline at end of file +// nba_cup(r); diff --git a/tasks/7_kyu.js b/tasks/7_kyu.js index 0722857..2cee0b1 100644 --- a/tasks/7_kyu.js +++ b/tasks/7_kyu.js @@ -4,4 +4,4 @@ define(function() { return times > 0 ? [number].concat(replicate(times - 1, number)) : []; } } -}); \ No newline at end of file +}); diff --git a/tasks/8_kyu.js b/tasks/8_kyu.js index a06a815..69ef7d1 100644 --- a/tasks/8_kyu.js +++ b/tasks/8_kyu.js @@ -18,4 +18,4 @@ define(function() { }) } } -}); \ No newline at end of file +}); diff --git a/tasks/template.js b/tasks/template.js index 3bc65d4..40ea3dc 100644 --- a/tasks/template.js +++ b/tasks/template.js @@ -1,7 +1,7 @@ -define(function() { - return { - print: function(msg) { - // console.log(msg); - } - }; -}); \ No newline at end of file +// define(function() { +// return { +// print: function(msg) { +// // console.log(msg); +// } +// }; +// }); \ No newline at end of file From 606e27dbb9819173c0a9ffb0feca6c6b36d70cc5 Mon Sep 17 00:00:00 2001 From: Nadiia Chorna Date: Wed, 29 May 2019 10:44:29 +0300 Subject: [PATCH 11/17] add space --- .eslintrc.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.eslintrc.js b/.eslintrc.js index a8ea689..fe152c8 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -13,5 +13,7 @@ module.exports = { "ecmaVersion": 2018, "sourceType": "module" }, - "rules": {} + "rules": { + + } }; \ No newline at end of file From c0806e966eae04232513def31ff931b1afc8fffa Mon Sep 17 00:00:00 2001 From: Nadiia Chorna Date: Wed, 29 May 2019 11:04:00 +0300 Subject: [PATCH 12/17] changed package.json --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index c4ef32b..085b793 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "codewarstasks", "version": "1.0.0", "description": "", - "main": "main.js", + "main": "index.js", "dependencies": { "amd-loader": "0.0.8", "requirejs": "^2.3.6" @@ -24,4 +24,4 @@ "url": "https://github.com/lv-411-nodejs/codeWarsTasks/issues" }, "homepage": "https://github.com/lv-411-nodejs/codeWarsTasks#readme" -} \ No newline at end of file +} From b337ade0d053b4c133031f64979c0c5ffae992f3 Mon Sep 17 00:00:00 2001 From: Nadiia Chorna Date: Wed, 29 May 2019 11:15:51 +0300 Subject: [PATCH 13/17] resolved err --- main.js | 2 +- package.json | 2 +- tasks/7_kyu.js | 2 +- tasks/8_kyu.js | 14 +++++++------- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/main.js b/main.js index 2e91fe7..5cea4da 100644 --- a/main.js +++ b/main.js @@ -3,7 +3,7 @@ require("amd-loader"); //msg.print("run!"); var kyu8 = require('./tasks/8_kyu'); -console.log(kyu8.fixTheMeerkat(['tail', 'body', 'head'])); +//console.log(kyu8.fixTheMeerkat(['tail', 'body', 'head'])); console.log(kyu8.squareOrSquareRoot([4, 3, 9, 7, 2, 1])); var kyu7 = require('./tasks/7_kyu'); diff --git a/package.json b/package.json index 085b793..a75234d 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "codewarstasks", "version": "1.0.0", "description": "", - "main": "index.js", + "main": "main.js", "dependencies": { "amd-loader": "0.0.8", "requirejs": "^2.3.6" diff --git a/tasks/7_kyu.js b/tasks/7_kyu.js index 2cee0b1..b859e63 100644 --- a/tasks/7_kyu.js +++ b/tasks/7_kyu.js @@ -1,6 +1,6 @@ define(function() { return { - replicate: function(times, number) { + replicate: function replicate(times, number) { return times > 0 ? [number].concat(replicate(times - 1, number)) : []; } } diff --git a/tasks/8_kyu.js b/tasks/8_kyu.js index 69ef7d1..fa824c8 100644 --- a/tasks/8_kyu.js +++ b/tasks/8_kyu.js @@ -1,12 +1,12 @@ // -------------- 1 ---------------- -define(function() { - return { - fixTheMeerkat: function(arr) { - return arr.reverse(); - } - } -}); +// define(function() { +// return { +// fixTheMeerkat: function(arr) { +// return arr.reverse(); +// } +// } +// }); // -------------- 2 ---------------- From 2e3facb8febf790cb6bb3c386f682b2d3db2d28a Mon Sep 17 00:00:00 2001 From: Nadiia Chorna Date: Wed, 29 May 2019 11:20:00 +0300 Subject: [PATCH 14/17] add fixTheMeerkat function --- main.js | 2 +- tasks/8_kyu.js | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/main.js b/main.js index 5cea4da..2e91fe7 100644 --- a/main.js +++ b/main.js @@ -3,7 +3,7 @@ require("amd-loader"); //msg.print("run!"); var kyu8 = require('./tasks/8_kyu'); -//console.log(kyu8.fixTheMeerkat(['tail', 'body', 'head'])); +console.log(kyu8.fixTheMeerkat(['tail', 'body', 'head'])); console.log(kyu8.squareOrSquareRoot([4, 3, 9, 7, 2, 1])); var kyu7 = require('./tasks/7_kyu'); diff --git a/tasks/8_kyu.js b/tasks/8_kyu.js index fa824c8..6db7614 100644 --- a/tasks/8_kyu.js +++ b/tasks/8_kyu.js @@ -16,6 +16,9 @@ define(function() { return arr.map((el) => { return Number.isInteger(Math.sqrt(el)) ? Math.sqrt(el) : Math.pow(el, 2); }) + }, + fixTheMeerkat: function(arr) { + return arr.reverse(); } } }); From 9a62b11b70664bef5d2d6871ba19d728d280f40e Mon Sep 17 00:00:00 2001 From: Nadiia Chorna Date: Wed, 29 May 2019 11:22:56 +0300 Subject: [PATCH 15/17] add spaces --- tasks/8_kyu.js | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/tasks/8_kyu.js b/tasks/8_kyu.js index 6db7614..2308517 100644 --- a/tasks/8_kyu.js +++ b/tasks/8_kyu.js @@ -1,15 +1,3 @@ -// -------------- 1 ---------------- - -// define(function() { -// return { -// fixTheMeerkat: function(arr) { -// return arr.reverse(); -// } -// } -// }); - -// -------------- 2 ---------------- - define(function() { return { squareOrSquareRoot: function(arr) { @@ -18,7 +6,7 @@ define(function() { }) }, fixTheMeerkat: function(arr) { - return arr.reverse(); + return arr.reverse(); } } }); From 0f7542ddb959a40aad6b930321e9f61753b6b100 Mon Sep 17 00:00:00 2001 From: Nadiia Chorna Date: Wed, 29 May 2019 23:30:35 +0300 Subject: [PATCH 16/17] added "Ranking NBA teams" task --- tasks/6_kyu.js | 43 ++++++++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/tasks/6_kyu.js b/tasks/6_kyu.js index d3bef2f..6e272c6 100644 --- a/tasks/6_kyu.js +++ b/tasks/6_kyu.js @@ -1,14 +1,31 @@ -// r = 'Los Angeles Clippers 104 Dallas Mavericks 88,New York Knicks 101 Atlanta Hawks 112,Indiana Pacers 103 Memphis Grizzlies 112, Los Angeles Clippers 100 Boston Celtics 120'; +define(function() { + return { + nba_cup: function(report, teamName) { + var w = 0; + var d = 0; + var l = 0; + var score = 0; + var conceded = 0; + var points = 0; + let reg = new RegExp('\\b' + teamName + '\\b', 'ig'); + let games = report.split(',').filter((item) => { + return item.match(reg); + }).map((item) => { + return item.trim().split(/\s*(\d+\.?\d*\b)\s*/).slice(0, -1); + }); + if (games.length < 1) { + return `${team}:This team didn't play!` + } + let sortgames = games.map((arr) => { + return arr.indexOf(teamName) == 0 ? arr : arr = [arr[2], arr[3], arr[0], arr[1]]; + }); + sortgames.forEach((game) => { + +game[1] > +game[3] ? w += 1 : (+game[1] < +game[3] ? l += 1 : d += 1) + score += +game[1]; + conceded += +game[3]; -// function nba_cup(str, team){ -// let w, d, l, scored, conceded, points; - -// let arr = str.split(',') -// .map((item)=>{ -// return item.match(/([a-zA-Z\s]+)([0-9]+)/ig); -// }) - -// console.log(arr); -// } - -// nba_cup(r); + }); + return `${teamName}:W=${w};D=${d};L=${l};Scored=${score};Conceded=${conceded};Points=${w*3+d}`; + } + } +}); From cf97b67b1f4c8e9095ddb1dc5be3ae6d9b777d38 Mon Sep 17 00:00:00 2001 From: Nadiia Chorna Date: Wed, 29 May 2019 23:35:25 +0300 Subject: [PATCH 17/17] deleted "points" variable --- tasks/6_kyu.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tasks/6_kyu.js b/tasks/6_kyu.js index 6e272c6..bf423be 100644 --- a/tasks/6_kyu.js +++ b/tasks/6_kyu.js @@ -6,7 +6,6 @@ define(function() { var l = 0; var score = 0; var conceded = 0; - var points = 0; let reg = new RegExp('\\b' + teamName + '\\b', 'ig'); let games = report.split(',').filter((item) => { return item.match(reg); @@ -14,7 +13,7 @@ define(function() { return item.trim().split(/\s*(\d+\.?\d*\b)\s*/).slice(0, -1); }); if (games.length < 1) { - return `${team}:This team didn't play!` + return `${teamName}:This team didn't play!` } let sortgames = games.map((arr) => { return arr.indexOf(teamName) == 0 ? arr : arr = [arr[2], arr[3], arr[0], arr[1]];