From 45225cdba23c0e1464a0b9fc3feda7a663c317b6 Mon Sep 17 00:00:00 2001 From: Gennady Tabala Date: Sun, 28 Jun 2020 22:27:16 +0100 Subject: [PATCH 01/12] First commit --- week-3/1-exercises/A-array-find/exercise.js | 3 +++ week-3/2-mandatory/1-oxygen-levels.js | 3 ++- week-3/2-mandatory/2-bush-berries.js | 7 +++++-- week-3/2-mandatory/3-space-colonies.js | 3 ++- week-3/2-mandatory/4-eligible-students.js | 4 ++-- week-3/2-mandatory/5-journey-planner.js | 4 ++-- week-3/2-mandatory/6-lane-names.js | 4 ++-- 7 files changed, 18 insertions(+), 10 deletions(-) diff --git a/week-3/1-exercises/A-array-find/exercise.js b/week-3/1-exercises/A-array-find/exercise.js index d7fd51f..b45dca2 100644 --- a/week-3/1-exercises/A-array-find/exercise.js +++ b/week-3/1-exercises/A-array-find/exercise.js @@ -4,6 +4,9 @@ */ // write your code here +function findLongNameThatStartsWithA(arr){ + return arr.find(item => item.startsWith("A") && item.length > 7); +} var names = ["Rakesh", "Antonio", "Alexandra", "Andronicus", "Annam", "Mikey", "Anastasia", "Karim", "Ahmed"]; diff --git a/week-3/2-mandatory/1-oxygen-levels.js b/week-3/2-mandatory/1-oxygen-levels.js index 3c02135..eae5382 100644 --- a/week-3/2-mandatory/1-oxygen-levels.js +++ b/week-3/2-mandatory/1-oxygen-levels.js @@ -9,7 +9,8 @@ To be safe, they need to land on the first unamed planet that has Oxygen levels Write a function that finds the oxygen level of the first safe planet - Oxygen between 19.5% and 23.5% */ -function safeLevels() { +function safeLevels(arr) { + return arr.find(oxLevel => parseFloat(oxLevel) > 19.5 && parseFloat(oxLevel) < 23.5); } diff --git a/week-3/2-mandatory/2-bush-berries.js b/week-3/2-mandatory/2-bush-berries.js index d900323..49b7cf9 100644 --- a/week-3/2-mandatory/2-bush-berries.js +++ b/week-3/2-mandatory/2-bush-berries.js @@ -10,8 +10,11 @@ Use the tests to confirm which message to return */ -function bushChecker() { - +function bushChecker(arr) { + if(arr.find(berryColor => berryColor != "pink") === undefined){ + return "Bush is safe to eat from"; + } + return "Toxic! Leave bush alone!"; } /* ======= TESTS - DO NOT MODIFY ===== */ diff --git a/week-3/2-mandatory/3-space-colonies.js b/week-3/2-mandatory/3-space-colonies.js index f99891a..b45f242 100644 --- a/week-3/2-mandatory/3-space-colonies.js +++ b/week-3/2-mandatory/3-space-colonies.js @@ -8,7 +8,8 @@ NOTE: don't include any element that is not a "family". */ -function colonisers() { +function colonisers(arr) { + return arr.filter(item => item.startsWith("A") && item.includes("family")); } diff --git a/week-3/2-mandatory/4-eligible-students.js b/week-3/2-mandatory/4-eligible-students.js index 6424b01..0e9031b 100644 --- a/week-3/2-mandatory/4-eligible-students.js +++ b/week-3/2-mandatory/4-eligible-students.js @@ -7,8 +7,8 @@ - Returns an array containing only the names of the who have attended AT LEAST 8 classes */ -function eligibleStudents() { - +function eligibleStudents(arr) { + return arr.filter(item => item[1] > 7).map(item => item[0]); } /* ======= TESTS - DO NOT MODIFY ===== */ diff --git a/week-3/2-mandatory/5-journey-planner.js b/week-3/2-mandatory/5-journey-planner.js index 53499c3..612175f 100644 --- a/week-3/2-mandatory/5-journey-planner.js +++ b/week-3/2-mandatory/5-journey-planner.js @@ -7,8 +7,8 @@ NOTE: only the names should be returned, not the means of transport. */ -function journeyPlanner() { - +function journeyPlanner(arr, by) { + return arr.filter(item => item.includes(by)).map(item => item[0]); } /* ======= TESTS - DO NOT MODIFY ===== */ diff --git a/week-3/2-mandatory/6-lane-names.js b/week-3/2-mandatory/6-lane-names.js index eddfe44..cce51a8 100644 --- a/week-3/2-mandatory/6-lane-names.js +++ b/week-3/2-mandatory/6-lane-names.js @@ -4,8 +4,8 @@ Write a function that will return all street names which contain 'Lane' in their name. */ -function getLanes() { - +function getLanes(arr) { + return arr.filter(item => item.includes("Lane")); } /* ======= TESTS - DO NOT MODIFY ===== */ From 1d09b5cb4eb496394905946ffe6fc5988554d29e Mon Sep 17 00:00:00 2001 From: Gennady Tabala Date: Tue, 30 Jun 2020 21:20:18 +0100 Subject: [PATCH 02/12] Second commit --- week-3/1-exercises/B-array-some/exercise.js | 4 ++++ week-3/1-exercises/C-array-every/exercise.js | 2 +- week-3/1-exercises/D-array-filter/exercise.js | 2 +- week-3/1-exercises/E-array-map/exercise.js | 23 +++++++++++++++++++ week-3/2-mandatory/2-bush-berries.js | 8 +++---- week-3/2-mandatory/7-password-validator.js | 17 +++++++++++++- 6 files changed, 49 insertions(+), 7 deletions(-) diff --git a/week-3/1-exercises/B-array-some/exercise.js b/week-3/1-exercises/B-array-some/exercise.js index 965c052..5213fbc 100644 --- a/week-3/1-exercises/B-array-some/exercise.js +++ b/week-3/1-exercises/B-array-some/exercise.js @@ -11,6 +11,10 @@ var pairsByIndex = [[0, 3], [1, 2], [2, 1], null, [3, 0]]; // If there is a null value in the array exit the program with the error code // https://nodejs.org/api/process.html#process_process_exit_code // process.exit(1); +if(pairsByIndex.some(item => item === null)){ + process.exit(1); +} + var students = ["Islam", "Lesley", "Harun", "Rukmini"]; var mentors = ["Daniel", "Irina", "Mozafar", "Luke"]; diff --git a/week-3/1-exercises/C-array-every/exercise.js b/week-3/1-exercises/C-array-every/exercise.js index b515e94..bbb94f6 100644 --- a/week-3/1-exercises/C-array-every/exercise.js +++ b/week-3/1-exercises/C-array-every/exercise.js @@ -5,7 +5,7 @@ var students = ["Omar", "Austine", "Dany", "Swathi", "Lesley", "Rukmini"]; var group = ["Austine", "Dany", "Swathi", "Daniel"]; -var groupIsOnlyStudents; // complete this statement +var groupIsOnlyStudents = group.every(item => students.find(student => student === item)); // complete this statement if (groupIsOnlyStudents) { console.log("The group contains only students"); diff --git a/week-3/1-exercises/D-array-filter/exercise.js b/week-3/1-exercises/D-array-filter/exercise.js index 6e32cc6..199598a 100644 --- a/week-3/1-exercises/D-array-filter/exercise.js +++ b/week-3/1-exercises/D-array-filter/exercise.js @@ -8,7 +8,7 @@ var pairsByIndexRaw = [[0, 3], [1, 2], [2, 1], null, [1], false, "whoops"]; -var pairsByIndex; // Complete this statement +var pairsByIndex = pairsByIndexRaw.filter(item => Array.isArray(item) && item.length === 2 ); // Complete this statement var students = ["Islam", "Lesley", "Harun", "Rukmini"]; var mentors = ["Daniel", "Irina", "Mozafar", "Luke"]; diff --git a/week-3/1-exercises/E-array-map/exercise.js b/week-3/1-exercises/E-array-map/exercise.js index 2835e92..d0e49dc 100644 --- a/week-3/1-exercises/E-array-map/exercise.js +++ b/week-3/1-exercises/E-array-map/exercise.js @@ -3,3 +3,26 @@ var numbers = [0.1, 0.2, 0.3, 0.4, 0.5]; +function multiplyByHundred(item){ + return item * 100; +} + +let numbers1 = numbers.map(multiplyByHundred); + +console.log(numbers1); + +let numbers2 = numbers.map(function multiplyBy100(item){return item * 100;}); + +console.log(numbers2); + +let numbers3 = numbers.map(function (item){return item * 100;}); + +console.log(numbers3); + +let numbers4 = numbers.map(item => {return item * 100;}); + +console.log(numbers4); + +let numbers5 = numbers.map(item => item * 100); + +console.log(numbers5); \ No newline at end of file diff --git a/week-3/2-mandatory/2-bush-berries.js b/week-3/2-mandatory/2-bush-berries.js index 49b7cf9..223afd0 100644 --- a/week-3/2-mandatory/2-bush-berries.js +++ b/week-3/2-mandatory/2-bush-berries.js @@ -11,10 +11,10 @@ */ function bushChecker(arr) { - if(arr.find(berryColor => berryColor != "pink") === undefined){ - return "Bush is safe to eat from"; - } - return "Toxic! Leave bush alone!"; + if(arr.some(berryColor => berryColor != "pink")){ + return "Toxic! Leave bush alone!"; + } + return "Bush is safe to eat from"; } /* ======= TESTS - DO NOT MODIFY ===== */ diff --git a/week-3/2-mandatory/7-password-validator.js b/week-3/2-mandatory/7-password-validator.js index 57b3d53..accd921 100644 --- a/week-3/2-mandatory/7-password-validator.js +++ b/week-3/2-mandatory/7-password-validator.js @@ -21,9 +21,24 @@ Expected Result: PasswordValidationResult= [false, false, false, false, true] */ +function checkPassword(password){ -function validatePasswords(passwords) { + let passwordArray = password.split(""); + + + return password.length > 5 && + passwordArray.some(item => item >= "A" && item <= "Z") && + passwordArray.some(item => item >= "a" && item <= "z") && + passwordArray.some(item => item >= "0" && item <= "9") && + passwordArray.some(item =>["!", "#", "$", "%", "."].indexOf(item) >= 0) && + passwordArray.some(item =>(item >= "A" && item <= "Z") || (item >= "a" && item <= "z") || + (item >= "0" && item <= "9") || ["!", "#", "$", "%", "."].indexOf(item) >= 0); +} + +function validatePasswords(passwords) { + console.log(passwords.map(checkPassword)); + //return passwords.map(checkPassword); } /* ======= TESTS - DO NOT MODIFY ===== */ From 2569b660afdf1ea710901208ff2e1bc677824db6 Mon Sep 17 00:00:00 2001 From: Gennady Tabala Date: Tue, 30 Jun 2020 21:28:32 +0100 Subject: [PATCH 03/12] Update 7-password-validator.js --- week-3/2-mandatory/7-password-validator.js | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/week-3/2-mandatory/7-password-validator.js b/week-3/2-mandatory/7-password-validator.js index accd921..a49da8e 100644 --- a/week-3/2-mandatory/7-password-validator.js +++ b/week-3/2-mandatory/7-password-validator.js @@ -21,24 +21,22 @@ Expected Result: PasswordValidationResult= [false, false, false, false, true] */ -function checkPassword(password){ + + + +function validatePasswords(passwords) { + return passwords.map((password) => { let passwordArray = password.split(""); - - + return password.length > 5 && passwordArray.some(item => item >= "A" && item <= "Z") && passwordArray.some(item => item >= "a" && item <= "z") && passwordArray.some(item => item >= "0" && item <= "9") && passwordArray.some(item =>["!", "#", "$", "%", "."].indexOf(item) >= 0) && - passwordArray.some(item =>(item >= "A" && item <= "Z") || (item >= "a" && item <= "z") || + passwordArray.some(item =>(item >= "A" && item <= "Z") || (item >= "a" && item <= "z") || (item >= "0" && item <= "9") || ["!", "#", "$", "%", "."].indexOf(item) >= 0); -} - - -function validatePasswords(passwords) { - console.log(passwords.map(checkPassword)); - //return passwords.map(checkPassword); +}); } /* ======= TESTS - DO NOT MODIFY ===== */ @@ -79,6 +77,6 @@ test( test( "validatePasswords function works - case 2", arraysEqual( - validatePasswords(passwords2), [true, true, false, false, false] + validatePasswords(passwords2), [true, true, false, false, false] // The right array is [true, true, true, false, true] ) ); From 6126155d8622bc23130b9d65543690909f0ea7a3 Mon Sep 17 00:00:00 2001 From: Gennady Tabala Date: Tue, 30 Jun 2020 21:58:53 +0100 Subject: [PATCH 04/12] Update 7-password-validator.js --- week-3/2-mandatory/7-password-validator.js | 26 +++++++++++++++------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/week-3/2-mandatory/7-password-validator.js b/week-3/2-mandatory/7-password-validator.js index a49da8e..ea5c77c 100644 --- a/week-3/2-mandatory/7-password-validator.js +++ b/week-3/2-mandatory/7-password-validator.js @@ -21,11 +21,10 @@ Expected Result: PasswordValidationResult= [false, false, false, false, true] */ - - - -function validatePasswords(passwords) { - return passwords.map((password) => { +function checkPassword(password){ + if(password === false){ + return false; + } let passwordArray = password.split(""); @@ -34,9 +33,20 @@ function validatePasswords(passwords) { passwordArray.some(item => item >= "a" && item <= "z") && passwordArray.some(item => item >= "0" && item <= "9") && passwordArray.some(item =>["!", "#", "$", "%", "."].indexOf(item) >= 0) && - passwordArray.some(item =>(item >= "A" && item <= "Z") || (item >= "a" && item <= "z") || + passwordArray.some(item =>(item >= "A" && item <= "Z") || (item >= "a" && item <= "z") || (item >= "0" && item <= "9") || ["!", "#", "$", "%", "."].indexOf(item) >= 0); -}); +} + + +function validatePasswords(passwords) { + + for(let i = 0; i < passwords.length; i++){ + if(i !== passwords.indexOf(passwords[i])) { + passwords[i] = false; + } + } + //console.log(passwords.map(checkPassword)); + return passwords.map(checkPassword); } /* ======= TESTS - DO NOT MODIFY ===== */ @@ -77,6 +87,6 @@ test( test( "validatePasswords function works - case 2", arraysEqual( - validatePasswords(passwords2), [true, true, false, false, false] // The right array is [true, true, true, false, true] + validatePasswords(passwords2), [true, true, false, false, false] ) ); From fe16c6ea2fbe82c719478ad525cdfed28643f778 Mon Sep 17 00:00:00 2001 From: Gennady Tabala Date: Wed, 1 Jul 2020 17:30:27 +0100 Subject: [PATCH 05/12] Excercise F and Password validator(final?) --- .../1-exercises/F-array-forEach/exercise.js | 11 ++++- week-3/2-mandatory/7-password-validator.js | 43 +++++++++---------- 2 files changed, 30 insertions(+), 24 deletions(-) diff --git a/week-3/1-exercises/F-array-forEach/exercise.js b/week-3/1-exercises/F-array-forEach/exercise.js index e83e2df..0921bc4 100644 --- a/week-3/1-exercises/F-array-forEach/exercise.js +++ b/week-3/1-exercises/F-array-forEach/exercise.js @@ -8,7 +8,16 @@ */ var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]; - +arr.forEach((item) => { + if(item % 3 === 0 && item % 5 === 0){ + console.log("FizzBuzz"); + }else if (item % 3 === 0){ + console.log("Fizz"); + }else if(item % 5 === 0){ + console.log("Buzz"); + }else {console.log(item);} + } + ); /* EXPECTED OUTPUT */ /* diff --git a/week-3/2-mandatory/7-password-validator.js b/week-3/2-mandatory/7-password-validator.js index ea5c77c..c6c2ba9 100644 --- a/week-3/2-mandatory/7-password-validator.js +++ b/week-3/2-mandatory/7-password-validator.js @@ -21,32 +21,29 @@ Expected Result: PasswordValidationResult= [false, false, false, false, true] */ -function checkPassword(password){ - if(password === false){ - return false; - } - - let passwordArray = password.split(""); - - return password.length > 5 && - passwordArray.some(item => item >= "A" && item <= "Z") && - passwordArray.some(item => item >= "a" && item <= "z") && - passwordArray.some(item => item >= "0" && item <= "9") && - passwordArray.some(item =>["!", "#", "$", "%", "."].indexOf(item) >= 0) && - passwordArray.some(item =>(item >= "A" && item <= "Z") || (item >= "a" && item <= "z") || - (item >= "0" && item <= "9") || ["!", "#", "$", "%", "."].indexOf(item) >= 0); -} function validatePasswords(passwords) { - - for(let i = 0; i < passwords.length; i++){ - if(i !== passwords.indexOf(passwords[i])) { - passwords[i] = false; - } - } - //console.log(passwords.map(checkPassword)); - return passwords.map(checkPassword); + return passwords.map((password,index,arr) => { + + let passwordArray = password.split(""); + + return password.length > 5 && // check the min length of password + // check if the password have uppercase letter + passwordArray.some(item => item >= "A" && item <= "Z") && + // check if the password have lowercase letter + passwordArray.some(item => item >= "a" && item <= "z") && + // check if the password have number + passwordArray.some(item => item >= "0" && item <= "9") && + // check if the password have special symbols + passwordArray.some(item =>["!", "#", "$", "%", "."].includes(item)) && + /* this validation for exception of all symbols that are not English alphabet symbols, + not numbers or non-alphanumeric symbols ("!", "#", "$", "%", "."). */ + passwordArray.every(item =>(item >= "A" && item <= "Z") || (item >= "a" && item <= "z") || + (item >= "0" && item <= "9") || ["!", "#", "$", "%", "."].includes(item)) && + // check if the password is duplicated + index === arr.indexOf(password); + }); } /* ======= TESTS - DO NOT MODIFY ===== */ From a38d1b6197cdbfb36f608cf6e7b244edf4e87cf5 Mon Sep 17 00:00:00 2001 From: Gennady Tabala Date: Wed, 1 Jul 2020 18:12:46 +0100 Subject: [PATCH 06/12] Final! Password validator. --- week-3/2-mandatory/7-password-validator.js | 60 +++++++++++++++------- 1 file changed, 41 insertions(+), 19 deletions(-) diff --git a/week-3/2-mandatory/7-password-validator.js b/week-3/2-mandatory/7-password-validator.js index c6c2ba9..47a0f87 100644 --- a/week-3/2-mandatory/7-password-validator.js +++ b/week-3/2-mandatory/7-password-validator.js @@ -22,28 +22,50 @@ PasswordValidationResult= [false, false, false, false, true] */ +// looks great but does a lot of extra work +// function validatePasswords(passwords) { +// return passwords.map((password,index,arr) => { +// let passwordArray = password.split(""); + +// return password.length > 5 && // check the min length of password +// // check if the password have uppercase letter +// passwordArray.some(item => item >= "A" && item <= "Z") && +// // check if the password have lowercase letter +// passwordArray.some(item => item >= "a" && item <= "z") && +// // check if the password have number +// passwordArray.some(item => item >= "0" && item <= "9") && +// // check if the password have special symbols +// passwordArray.some(item =>["!", "#", "$", "%", "."].includes(item)) && +// /* this validation for exception of all symbols that are not English alphabet symbols, +// not numbers or non-alphanumeric symbols ("!", "#", "$", "%", "."). */ +// passwordArray.every(item =>(item >= "A" && item <= "Z") || (item >= "a" && item <= "z") || +// (item >= "0" && item <= "9") || ["!", "#", "$", "%", "."].includes(item)) && +// // check if the password is duplicated +// index === arr.indexOf(password); +// }); +// } function validatePasswords(passwords) { - return passwords.map((password,index,arr) => { + return passwords.map((password,index,arr) => { - let passwordArray = password.split(""); - - return password.length > 5 && // check the min length of password - // check if the password have uppercase letter - passwordArray.some(item => item >= "A" && item <= "Z") && - // check if the password have lowercase letter - passwordArray.some(item => item >= "a" && item <= "z") && - // check if the password have number - passwordArray.some(item => item >= "0" && item <= "9") && - // check if the password have special symbols - passwordArray.some(item =>["!", "#", "$", "%", "."].includes(item)) && - /* this validation for exception of all symbols that are not English alphabet symbols, - not numbers or non-alphanumeric symbols ("!", "#", "$", "%", "."). */ - passwordArray.every(item =>(item >= "A" && item <= "Z") || (item >= "a" && item <= "z") || - (item >= "0" && item <= "9") || ["!", "#", "$", "%", "."].includes(item)) && - // check if the password is duplicated - index === arr.indexOf(password); - }); + // check if the password is duplicated and the min length of password + if(index !== arr.indexOf(password) || password.length < 5){ + return false; + }; + let passwordArray = password.split(""); + + return passwordArray.some(item => item >= "A" && item <= "Z") && // check if the password have uppercase letter + // check if the password have lowercase letter + passwordArray.some(item => item >= "a" && item <= "z") && + // check if the password have number + passwordArray.some(item => item >= "0" && item <= "9") && + // check if the password have special symbols + passwordArray.some(item =>["!", "#", "$", "%", "."].includes(item)) && + /* this validation for exception of all symbols that are not English alphabet symbols, + not numbers or non-alphanumeric symbols ("!", "#", "$", "%", "."). */ + passwordArray.every(item =>(item >= "A" && item <= "Z") || (item >= "a" && item <= "z") || + (item >= "0" && item <= "9") || ["!", "#", "$", "%", "."].includes(item)); + }); } /* ======= TESTS - DO NOT MODIFY ===== */ From 1f99f16123660d33718b1ab804bb9d983b15be70 Mon Sep 17 00:00:00 2001 From: Gennady Tabala Date: Thu, 2 Jul 2020 18:50:13 +0100 Subject: [PATCH 07/12] all mandatory exercises --- .../1-exercises/G-array-methods/exercise.js | 2 +- .../1-exercises/G-array-methods/exercise2.js | 2 +- .../1-exercises/H-array-methods-2/exercise.js | 4 +- .../H-array-methods-2/exercise2.js | 6 +- .../H-array-methods-2/exercise3.js | 2 +- week-3/2-mandatory/7-password-validator.js | 63 ++++++------------- week-3/3-extra/card-validator.js | 28 +++++++++ 7 files changed, 58 insertions(+), 49 deletions(-) create mode 100644 week-3/3-extra/card-validator.js diff --git a/week-3/1-exercises/G-array-methods/exercise.js b/week-3/1-exercises/G-array-methods/exercise.js index 44e9c80..6a8e4b3 100644 --- a/week-3/1-exercises/G-array-methods/exercise.js +++ b/week-3/1-exercises/G-array-methods/exercise.js @@ -4,7 +4,7 @@ */ var numbers = [3, 2, 1]; -var sortedNumbers; // complete this statement +var sortedNumbers = numbers.sort(); // complete this statement /* DO NOT EDIT BELOW THIS LINE diff --git a/week-3/1-exercises/G-array-methods/exercise2.js b/week-3/1-exercises/G-array-methods/exercise2.js index 3dd24a1..dd87089 100644 --- a/week-3/1-exercises/G-array-methods/exercise2.js +++ b/week-3/1-exercises/G-array-methods/exercise2.js @@ -7,7 +7,7 @@ var mentors = ["Daniel", "Irina", "Rares"]; var students = ["Rukmini", "Abdul", "Austine", "Swathi"]; -var everyone; // complete this statement +var everyone = mentors.concat(students); // complete this statement /* DO NOT EDIT BELOW THIS LINE diff --git a/week-3/1-exercises/H-array-methods-2/exercise.js b/week-3/1-exercises/H-array-methods-2/exercise.js index d36303b..3aa962b 100644 --- a/week-3/1-exercises/H-array-methods-2/exercise.js +++ b/week-3/1-exercises/H-array-methods-2/exercise.js @@ -15,8 +15,8 @@ var everyone = [ "Swathi" ]; -var firstFive; // complete this statement -var lastFive; // complete this statement +var firstFive = everyone.slice(0, 5); // complete this statement +var lastFive = everyone.slice(-5); // complete this statement /* DO NOT EDIT BELOW THIS LINE diff --git a/week-3/1-exercises/H-array-methods-2/exercise2.js b/week-3/1-exercises/H-array-methods-2/exercise2.js index b7be576..27e9e26 100644 --- a/week-3/1-exercises/H-array-methods-2/exercise2.js +++ b/week-3/1-exercises/H-array-methods-2/exercise2.js @@ -7,7 +7,11 @@ Tip: use the string method .split() and the array method .join() */ -function capitalise(str) {} +function capitalise(str) { + let arr = str.split(""); + arr[0] = arr[0].toUpperCase(); + return arr.join(""); +} /* DO NOT EDIT BELOW THIS LINE diff --git a/week-3/1-exercises/H-array-methods-2/exercise3.js b/week-3/1-exercises/H-array-methods-2/exercise3.js index 82e9dd8..75a6b76 100644 --- a/week-3/1-exercises/H-array-methods-2/exercise3.js +++ b/week-3/1-exercises/H-array-methods-2/exercise3.js @@ -7,7 +7,7 @@ var ukNations = ["Scotland", "Wales", "England", "Northern Ireland"]; function isInUK(country) { - return; // complete this statement + return ukNations.includes(country); // complete this statement } /* diff --git a/week-3/2-mandatory/7-password-validator.js b/week-3/2-mandatory/7-password-validator.js index 47a0f87..63e5fe5 100644 --- a/week-3/2-mandatory/7-password-validator.js +++ b/week-3/2-mandatory/7-password-validator.js @@ -21,53 +21,30 @@ Expected Result: PasswordValidationResult= [false, false, false, false, true] */ - -// looks great but does a lot of extra work -// function validatePasswords(passwords) { -// return passwords.map((password,index,arr) => { - -// let passwordArray = password.split(""); - -// return password.length > 5 && // check the min length of password -// // check if the password have uppercase letter -// passwordArray.some(item => item >= "A" && item <= "Z") && -// // check if the password have lowercase letter -// passwordArray.some(item => item >= "a" && item <= "z") && -// // check if the password have number -// passwordArray.some(item => item >= "0" && item <= "9") && -// // check if the password have special symbols -// passwordArray.some(item =>["!", "#", "$", "%", "."].includes(item)) && -// /* this validation for exception of all symbols that are not English alphabet symbols, -// not numbers or non-alphanumeric symbols ("!", "#", "$", "%", "."). */ -// passwordArray.every(item =>(item >= "A" && item <= "Z") || (item >= "a" && item <= "z") || -// (item >= "0" && item <= "9") || ["!", "#", "$", "%", "."].includes(item)) && -// // check if the password is duplicated -// index === arr.indexOf(password); -// }); -// } function validatePasswords(passwords) { - return passwords.map((password,index,arr) => { + return passwords.map((password,index,arr) => { - // check if the password is duplicated and the min length of password - if(index !== arr.indexOf(password) || password.length < 5){ - return false; - }; - let passwordArray = password.split(""); - - return passwordArray.some(item => item >= "A" && item <= "Z") && // check if the password have uppercase letter - // check if the password have lowercase letter - passwordArray.some(item => item >= "a" && item <= "z") && - // check if the password have number - passwordArray.some(item => item >= "0" && item <= "9") && - // check if the password have special symbols - passwordArray.some(item =>["!", "#", "$", "%", "."].includes(item)) && - /* this validation for exception of all symbols that are not English alphabet symbols, - not numbers or non-alphanumeric symbols ("!", "#", "$", "%", "."). */ - passwordArray.every(item =>(item >= "A" && item <= "Z") || (item >= "a" && item <= "z") || - (item >= "0" && item <= "9") || ["!", "#", "$", "%", "."].includes(item)); - }); + let passwordArray = password.split(""); + + return password.length > 5 && // check the min length of password + // check if the password is duplicated + index === arr.indexOf(password) && + // check if the password have uppercase letter + passwordArray.some(item => item >= "A" && item <= "Z") && + // check if the password have lowercase letter + passwordArray.some(item => item >= "a" && item <= "z") && + // check if the password have number + passwordArray.some(item => item >= "0" && item <= "9") && + // check if the password have special symbols + passwordArray.some(item =>["!", "#", "$", "%", "."].includes(item)) && + /* this validation for exception of all symbols that are not English alphabet symbols, + not numbers or non-alphanumeric symbols ("!", "#", "$", "%", "."). */ + passwordArray.every(item =>(item >= "A" && item <= "Z") || (item >= "a" && item <= "z") || + (item >= "0" && item <= "9") || ["!", "#", "$", "%", "."].includes(item)); + }); } + /* ======= TESTS - DO NOT MODIFY ===== */ const passwords1 = ["Se%5", "TktE.TJTU", "384#HsHF", "dvyyeyy!5", "tryT3729"] diff --git a/week-3/3-extra/card-validator.js b/week-3/3-extra/card-validator.js new file mode 100644 index 0000000..2f9546d --- /dev/null +++ b/week-3/3-extra/card-validator.js @@ -0,0 +1,28 @@ +// - Number must be 16 digits, all of them must be numbers +// - You must have at least two different digits represented (all of the digits cannot be the same) +// - The final digit must be even +// - The sum of all the digits must be greater than 16 + +function isBankCardValid(cardNumber){ + let numberArray = cardNumber.split(""); + + firstGroup = cardNumber.slice(0, 4); + secondGroup = cardNumber.slice(4, 8); + thirdGroup = cardNumber.slice(8, 12); + fourthGroup = cardNumber.slice(12); + if (numberArray.every(number => typeof number === "number")){ + return `The bank card number ${firstGroup} ${secondGroup} ${thirdGroup} ${fourthGroup} is not valid.`; + } + if(numberArray.reduce((accumulator, number) => accumulator + number) <= 16){ + return `The bank card number ${firstGroup} ${secondGroup} ${thirdGroup} ${fourthGroup} is not valid.`; + } + if(numberArray[15] % 2 === 1){ + return `The bank card number ${firstGroup} ${secondGroup} ${thirdGroup} ${fourthGroup} is not valid.`; + } + if(numberArray.every((number, index, arr) => number === numberArray[0])){ + return `The bank card number ${firstGroup} ${secondGroup} ${thirdGroup} ${fourthGroup} is not valid.`; + } + return `The bank card number ${firstGroup} ${secondGroup} ${thirdGroup} ${fourthGroup} is valid.`; + +} +console.log(isBankCardValid("00000000000000b7")); \ No newline at end of file From 231da57e2402376fbf9e54ca4a1ba4d54364416e Mon Sep 17 00:00:00 2001 From: Gennady Tabala Date: Thu, 2 Jul 2020 19:56:53 +0100 Subject: [PATCH 08/12] card validator. --- week-3/3-extra/card-validator.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/week-3/3-extra/card-validator.js b/week-3/3-extra/card-validator.js index 2f9546d..0a94cba 100644 --- a/week-3/3-extra/card-validator.js +++ b/week-3/3-extra/card-validator.js @@ -10,19 +10,22 @@ function isBankCardValid(cardNumber){ secondGroup = cardNumber.slice(4, 8); thirdGroup = cardNumber.slice(8, 12); fourthGroup = cardNumber.slice(12); - if (numberArray.every(number => typeof number === "number")){ - return `The bank card number ${firstGroup} ${secondGroup} ${thirdGroup} ${fourthGroup} is not valid.`; + if (numberArray.length !== 16){ + return `The bank card number ${firstGroup} ${secondGroup} ${thirdGroup} ${fourthGroup} is not valid.length`; } - if(numberArray.reduce((accumulator, number) => accumulator + number) <= 16){ - return `The bank card number ${firstGroup} ${secondGroup} ${thirdGroup} ${fourthGroup} is not valid.`; + if (numberArray.some(number => parseInt(number)+"" === "")){ + return `The bank card number ${firstGroup} ${secondGroup} ${thirdGroup} ${fourthGroup} is not valid.nn`; + } + if(numberArray.reduce((accumulator, number) => accumulator + parseInt(number)) <= 16){ + return `The bank card number ${firstGroup} ${secondGroup} ${thirdGroup} ${fourthGroup} is not valid 16.`; } if(numberArray[15] % 2 === 1){ - return `The bank card number ${firstGroup} ${secondGroup} ${thirdGroup} ${fourthGroup} is not valid.`; + return `The bank card number ${firstGroup} ${secondGroup} ${thirdGroup} ${fourthGroup} is not valid. even`; } if(numberArray.every((number, index, arr) => number === numberArray[0])){ - return `The bank card number ${firstGroup} ${secondGroup} ${thirdGroup} ${fourthGroup} is not valid.`; + return `The bank card number ${firstGroup} ${secondGroup} ${thirdGroup} ${fourthGroup} is not valid.9`; } return `The bank card number ${firstGroup} ${secondGroup} ${thirdGroup} ${fourthGroup} is valid.`; } -console.log(isBankCardValid("00000000000000b7")); \ No newline at end of file +console.log(isBankCardValid("888888888888n808")); \ No newline at end of file From 2a204dce97584474b6edf920c9734e31f922b3e9 Mon Sep 17 00:00:00 2001 From: Gennady Tabala Date: Thu, 2 Jul 2020 20:14:55 +0100 Subject: [PATCH 09/12] still not work --- week-3/3-extra/card-validator.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/week-3/3-extra/card-validator.js b/week-3/3-extra/card-validator.js index 0a94cba..813c92b 100644 --- a/week-3/3-extra/card-validator.js +++ b/week-3/3-extra/card-validator.js @@ -13,7 +13,7 @@ function isBankCardValid(cardNumber){ if (numberArray.length !== 16){ return `The bank card number ${firstGroup} ${secondGroup} ${thirdGroup} ${fourthGroup} is not valid.length`; } - if (numberArray.some(number => parseInt(number)+"" === "")){ + if (numberArray.some(number => typeof number !== "number")){ return `The bank card number ${firstGroup} ${secondGroup} ${thirdGroup} ${fourthGroup} is not valid.nn`; } if(numberArray.reduce((accumulator, number) => accumulator + parseInt(number)) <= 16){ From d8164d49af0e34c3c4556d781a28df7db0855a51 Mon Sep 17 00:00:00 2001 From: Gennady Tabala Date: Thu, 2 Jul 2020 22:35:06 +0100 Subject: [PATCH 10/12] It's still not working --- week-3/3-extra/card-validator.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/week-3/3-extra/card-validator.js b/week-3/3-extra/card-validator.js index 813c92b..e205375 100644 --- a/week-3/3-extra/card-validator.js +++ b/week-3/3-extra/card-validator.js @@ -13,19 +13,19 @@ function isBankCardValid(cardNumber){ if (numberArray.length !== 16){ return `The bank card number ${firstGroup} ${secondGroup} ${thirdGroup} ${fourthGroup} is not valid.length`; } - if (numberArray.some(number => typeof number !== "number")){ - return `The bank card number ${firstGroup} ${secondGroup} ${thirdGroup} ${fourthGroup} is not valid.nn`; + if (numberArray.some(number => typeof Number(number) !== "number")){ + return `The bank card number ${firstGroup} ${secondGroup} ${thirdGroup} ${fourthGroup} is not valid. There is non number characters.`; } if(numberArray.reduce((accumulator, number) => accumulator + parseInt(number)) <= 16){ - return `The bank card number ${firstGroup} ${secondGroup} ${thirdGroup} ${fourthGroup} is not valid 16.`; + return `The bank card number ${firstGroup} ${secondGroup} ${thirdGroup} ${fourthGroup} is not valid. The summ of numbers is lower than 16`; } if(numberArray[15] % 2 === 1){ - return `The bank card number ${firstGroup} ${secondGroup} ${thirdGroup} ${fourthGroup} is not valid. even`; + return `The bank card number ${firstGroup} ${secondGroup} ${thirdGroup} ${fourthGroup} is not valid. The last number is not even.`; } if(numberArray.every((number, index, arr) => number === numberArray[0])){ - return `The bank card number ${firstGroup} ${secondGroup} ${thirdGroup} ${fourthGroup} is not valid.9`; + return `The bank card number ${firstGroup} ${secondGroup} ${thirdGroup} ${fourthGroup} is not valid. All numbers the same.`; } return `The bank card number ${firstGroup} ${secondGroup} ${thirdGroup} ${fourthGroup} is valid.`; } -console.log(isBankCardValid("888888888888n808")); \ No newline at end of file +console.log(isBankCardValid("0000000000000022")); \ No newline at end of file From 0f3365fff8fe0a4fbf8931da84943b21275fbb8b Mon Sep 17 00:00:00 2001 From: Gennady Tabala Date: Sat, 4 Jul 2020 22:06:43 +0100 Subject: [PATCH 11/12] Update card-validator.js --- week-3/3-extra/card-validator.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/week-3/3-extra/card-validator.js b/week-3/3-extra/card-validator.js index e205375..5752ec9 100644 --- a/week-3/3-extra/card-validator.js +++ b/week-3/3-extra/card-validator.js @@ -12,20 +12,25 @@ function isBankCardValid(cardNumber){ fourthGroup = cardNumber.slice(12); if (numberArray.length !== 16){ return `The bank card number ${firstGroup} ${secondGroup} ${thirdGroup} ${fourthGroup} is not valid.length`; - } - if (numberArray.some(number => typeof Number(number) !== "number")){ + }// check if a length of card number equals 16 + if (numberArray.some(number => !(number >=0 && number <= 9))){ return `The bank card number ${firstGroup} ${secondGroup} ${thirdGroup} ${fourthGroup} is not valid. There is non number characters.`; - } - if(numberArray.reduce((accumulator, number) => accumulator + parseInt(number)) <= 16){ + }// check if all characters in card number are digit + if(numberArray.reduce((accumulator, number) => accumulator + parseInt(number),0) <= 16){ return `The bank card number ${firstGroup} ${secondGroup} ${thirdGroup} ${fourthGroup} is not valid. The summ of numbers is lower than 16`; - } + }// check if a summ of all digits is greater or equals to 16 if(numberArray[15] % 2 === 1){ return `The bank card number ${firstGroup} ${secondGroup} ${thirdGroup} ${fourthGroup} is not valid. The last number is not even.`; - } + }// check if the last is an even digit if(numberArray.every((number, index, arr) => number === numberArray[0])){ return `The bank card number ${firstGroup} ${secondGroup} ${thirdGroup} ${fourthGroup} is not valid. All numbers the same.`; - } + }// check if all didgits are the same return `The bank card number ${firstGroup} ${secondGroup} ${thirdGroup} ${fourthGroup} is valid.`; } -console.log(isBankCardValid("0000000000000022")); \ No newline at end of file +console.log(isBankCardValid("9999777788880000")); +console.log(isBankCardValid("6666666666661666")); +console.log(isBankCardValid("a92332119c011112")); +console.log(isBankCardValid("4444444444444444")); +console.log(isBankCardValid("1111111111111110")); +console.log(isBankCardValid("6666666666666661")); From bbd4a86a7b1bdd2d1bf3fd07a04dd0ec760a6fa6 Mon Sep 17 00:00:00 2001 From: Gennady Tabala Date: Sun, 13 Sep 2020 13:09:46 +0100 Subject: [PATCH 12/12] Ok --- week-3/2-mandatory/8-codewars.md | 4 +++- week-3/3-extra/card-validator.js | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/week-3/2-mandatory/8-codewars.md b/week-3/2-mandatory/8-codewars.md index 8bd2b85..11a0e17 100644 --- a/week-3/2-mandatory/8-codewars.md +++ b/week-3/2-mandatory/8-codewars.md @@ -30,4 +30,6 @@ Today, you'll be using a platform called [CodeWars](https://codewars.com) to hel - [people in bus](https://www.codewars.com/kata/number-of-people-in-the-bus/train/javascript) - [sum without highest and lowest](https://www.codewars.com/kata/sum-without-highest-and-lowest-number/train/javascript) - [reveersed array of digits](https://www.codewars.com/kata/convert-number-to-reversed-array-of-digits/train/javascript) -- [slash sum of negatives](https://www.codewars.com/kata/count-of-positives-slash-sum-of-negatives/train/javascript) \ No newline at end of file +- [slash sum of negatives](https://www.codewars.com/kata/count-of-positives-slash-sum-of-negatives/train/javascript) + + diff --git a/week-3/3-extra/card-validator.js b/week-3/3-extra/card-validator.js index 5752ec9..24aa5f2 100644 --- a/week-3/3-extra/card-validator.js +++ b/week-3/3-extra/card-validator.js @@ -34,3 +34,5 @@ console.log(isBankCardValid("a92332119c011112")); console.log(isBankCardValid("4444444444444444")); console.log(isBankCardValid("1111111111111110")); console.log(isBankCardValid("6666666666666661")); + +