From e7acc2f4bbcf780f5918831c69d73819f0dad47f Mon Sep 17 00:00:00 2001 From: Sadat Date: Wed, 1 Jul 2020 11:01:36 +0100 Subject: [PATCH 1/6] completed 2nd mandotory exercise --- week-3/2-mandatory/3-space-colonies.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/week-3/2-mandatory/3-space-colonies.js b/week-3/2-mandatory/3-space-colonies.js index f99891a..e97b03b 100644 --- a/week-3/2-mandatory/3-space-colonies.js +++ b/week-3/2-mandatory/3-space-colonies.js @@ -8,7 +8,9 @@ NOTE: don't include any element that is not a "family". */ -function colonisers() { +function colonisers(arr) { + let alphaSettlers = arr.filter(item => item.length > 9 && item.charAt(0) === 'A'); + return alphaSettlers; } From a26f8e8baf0f6b6f16ea04cb18458973ee9e7d5d Mon Sep 17 00:00:00 2001 From: Sadat Date: Wed, 1 Jul 2020 17:30:41 +0100 Subject: [PATCH 2/6] completed all the exercises (non mandatory) --- week-3/1-exercises/A-array-find/exercise.js | 5 ++ week-3/1-exercises/B-array-some/exercise.js | 26 +++++-- 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 | 14 ++++ .../1-exercises/F-array-forEach/exercise.js | 22 +++++- .../1-exercises/G-array-methods/exercise.js | 2 +- .../1-exercises/G-array-methods/exercise2.js | 2 +- .../1-exercises/H-array-methods-2/exercise.js | 16 ++-- .../H-array-methods-2/exercise2.js | 16 +++- .../H-array-methods-2/exercise3.js | 2 +- week-3/2-mandatory/1-oxygen-levels.js | 2 +- week-3/2-mandatory/2-bush-berries.js | 10 ++- week-3/2-mandatory/4-eligible-students.js | 77 +++++++++++-------- 14 files changed, 135 insertions(+), 63 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..52352b5 100644 --- a/week-3/1-exercises/A-array-find/exercise.js +++ b/week-3/1-exercises/A-array-find/exercise.js @@ -4,6 +4,11 @@ */ // write your code here +function findLongNameThatStartsWithA (arr){ + let beginsWithAOver7 = arr.find(x => x.charAt(0) === 'A' && x.length > 7); + return beginsWithAOver7; + +} var names = ["Rakesh", "Antonio", "Alexandra", "Andronicus", "Annam", "Mikey", "Anastasia", "Karim", "Ahmed"]; diff --git a/week-3/1-exercises/B-array-some/exercise.js b/week-3/1-exercises/B-array-some/exercise.js index 965c052..58243b9 100644 --- a/week-3/1-exercises/B-array-some/exercise.js +++ b/week-3/1-exercises/B-array-some/exercise.js @@ -11,14 +11,24 @@ 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); +function isNull(arr){ + let nullFound = arr.some(item => item === null); + + if(nullFound === true){ + return `Exiting program null found in array`; -var students = ["Islam", "Lesley", "Harun", "Rukmini"]; -var mentors = ["Daniel", "Irina", "Mozafar", "Luke"]; + }else { + return `Array is free from null value`; + } +} -var pairs = pairsByIndex.map(function(indexes) { - var student = students[indexes[0]]; - var mentor = mentors[indexes[1]]; - return [student, mentor]; -}); +// var students = ["Islam", "Lesley", "Harun", "Rukmini"]; +// var mentors = ["Daniel", "Irina", "Mozafar", "Luke"]; -console.log(pairs); +// var pairs = pairsByIndex.map(function(indexes) { +// var student = students[indexes[0]]; +// var mentor = mentors[indexes[1]]; +// return [student, mentor]; +// }); + +console.log(isNull(pairsByIndex)); diff --git a/week-3/1-exercises/C-array-every/exercise.js b/week-3/1-exercises/C-array-every/exercise.js index b515e94..2fb08e5 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(x => students.includes(x)); // 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..afeeef4 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(x => x === []); // 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..0f27d7b 100644 --- a/week-3/1-exercises/E-array-map/exercise.js +++ b/week-3/1-exercises/E-array-map/exercise.js @@ -3,3 +3,17 @@ var numbers = [0.1, 0.2, 0.3, 0.4, 0.5]; +//arrow function solution +let multiplied = numbers.map(x => x * 100); + + +//calling a function +function multiBy100(arr){ + let total = arr * 100; + return total; + +} + + +console.log(multiplied); +console.log(numbers.map(multiBy100)); \ No newline at end of file diff --git a/week-3/1-exercises/F-array-forEach/exercise.js b/week-3/1-exercises/F-array-forEach/exercise.js index e83e2df..d4871c1 100644 --- a/week-3/1-exercises/F-array-forEach/exercise.js +++ b/week-3/1-exercises/F-array-forEach/exercise.js @@ -7,7 +7,27 @@ An array with numbers 1-15 has been provided. */ -var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]; +var array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]; + + + +function fizzBuzz(arr){ + let result = arr.forEach(function(index){ + if(index % 3 === 0){ + console.log(`fizz`); + }else if (index % 5 === 0){ + console.log('buzz'); + }else{ + console.log(index); + } + + }); + + } + + + +console.log(fizzBuzz(array)); /* EXPECTED OUTPUT */ 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..69e155f 100644 --- a/week-3/1-exercises/H-array-methods-2/exercise.js +++ b/week-3/1-exercises/H-array-methods-2/exercise.js @@ -5,24 +5,18 @@ The variable `lastFive` should contain the last five items of `everyone` */ -var everyone = [ - "Daniel", - "Irina", - "Rares", - "Rukmini", - "Abdul", - "Austine", - "Swathi" -]; +var everyone = ["Daniel","Irina","Rares", "Rukmini", "Abdul", "Austine", "Swathi"]; -var firstFive; // complete this statement -var lastFive; // complete this statement +var firstFive = everyone.splice(0, 5); // complete this statement +var everyone = firstFive.concat(everyone); // complete this statement +var lastFive = everyone.splice(0, 2); /* DO NOT EDIT BELOW THIS LINE --------------------------- */ console.log(firstFive); +console.log(everyone); console.log(lastFive); /* 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..c515ae1 100644 --- a/week-3/1-exercises/H-array-methods-2/exercise2.js +++ b/week-3/1-exercises/H-array-methods-2/exercise2.js @@ -7,8 +7,20 @@ Tip: use the string method .split() and the array method .join() */ -function capitalise(str) {} - +function capitalise(str) { + //put word in array + let splitWord = str.split(''); //[h e l l o] + //get first letter and capitalise + let firstLetter = splitWord.splice(0, 1); //[h] + //change first letter to capital + let capLetter = firstLetter[0].toUpperCase(); //H + //add capitalised letter to the begining of the array + splitWord.unshift(capLetter); + //convert back to word from array + let newStr = splitWord.join(''); + return newStr; +} +//console.log(capitalise("gregory")); /* 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/1-oxygen-levels.js b/week-3/2-mandatory/1-oxygen-levels.js index 3c02135..94baa2f 100644 --- a/week-3/2-mandatory/1-oxygen-levels.js +++ b/week-3/2-mandatory/1-oxygen-levels.js @@ -9,7 +9,7 @@ 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) { } diff --git a/week-3/2-mandatory/2-bush-berries.js b/week-3/2-mandatory/2-bush-berries.js index d900323..880ca0c 100644 --- a/week-3/2-mandatory/2-bush-berries.js +++ b/week-3/2-mandatory/2-bush-berries.js @@ -10,8 +10,14 @@ Use the tests to confirm which message to return */ -function bushChecker() { - +function bushChecker(arr) { + let safeToEat = arr.every(item => item === 'pink'); + + if(safeToEat === true){ + return "Bush is safe to eat from"; + }else{ + return "Toxic! Leave bush alone!"; + } } /* ======= TESTS - DO NOT MODIFY ===== */ diff --git a/week-3/2-mandatory/4-eligible-students.js b/week-3/2-mandatory/4-eligible-students.js index 6424b01..7988155 100644 --- a/week-3/2-mandatory/4-eligible-students.js +++ b/week-3/2-mandatory/4-eligible-students.js @@ -6,13 +6,6 @@ (see tests to confirm how this data will be structured) - Returns an array containing only the names of the who have attended AT LEAST 8 classes */ - -function eligibleStudents() { - -} - -/* ======= TESTS - DO NOT MODIFY ===== */ - const attendances = [ ["Ahmed", 8], ["Clement", 10], @@ -20,33 +13,51 @@ const attendances = [ ["Adam", 7], ["Tayoa", 11], ["Nina", 10] -] +]; -function arraysEqual(a, b) { - if (a === b) return true; - if (a == null || b == null) return false; - if (a.length != b.length) return false; - - for (let i = 0; i < a.length; ++i) { - if (a[i] !== b[i]) return false; - } - - return true; -} -function test(test_name, expr) { - let status; - if (expr) { - status = "PASSED"; - } else { - status = "FAILED"; - } - - console.log(`${test_name}: ${status}`); +function eligibleStudents(arr) { + let examStudents = arr.filter(item => item.filter(item = item >= 8) ); + return examStudents; + } +console.log(eligibleStudents(attendances)); +/* ======= TESTS - DO NOT MODIFY ===== */ -test("eligibleStudents function works", - arraysEqual( - eligibleStudents(attendances), ["Ahmed", "Clement", "Tayoa", "Nina"] - ) -) \ No newline at end of file +// const attendances = [ +// ["Ahmed", 8], +// ["Clement", 10], +// ["Elamin", 6], +// ["Adam", 7], +// ["Tayoa", 11], +// ["Nina", 10] +// ] + +// function arraysEqual(a, b) { +// if (a === b) return true; +// if (a == null || b == null) return false; +// if (a.length != b.length) return false; + +// for (let i = 0; i < a.length; ++i) { +// if (a[i] !== b[i]) return false; +// } + +// return true; +// } + +// function test(test_name, expr) { +// let status; +// if (expr) { +// status = "PASSED"; +// } else { +// status = "FAILED"; +// } + +// console.log(`${test_name}: ${status}`); +// } + +// test("eligibleStudents function works", +// arraysEqual( +// eligibleStudents(attendances), ["Ahmed", "Clement", "Tayoa", "Nina"] +// ) +// ) \ No newline at end of file From a8b5a55b20f38c4bcd84738d6a3aee2ce23fc079 Mon Sep 17 00:00:00 2001 From: Sadat Date: Thu, 2 Jul 2020 14:59:35 +0100 Subject: [PATCH 3/6] completed eligible students exercise --- week-3/2-mandatory/1-oxygen-levels.js | 3 +- week-3/2-mandatory/4-eligible-students.js | 98 +++++++++++++---------- 2 files changed, 56 insertions(+), 45 deletions(-) diff --git a/week-3/2-mandatory/1-oxygen-levels.js b/week-3/2-mandatory/1-oxygen-levels.js index 94baa2f..97c3b7f 100644 --- a/week-3/2-mandatory/1-oxygen-levels.js +++ b/week-3/2-mandatory/1-oxygen-levels.js @@ -10,7 +10,8 @@ Write a function that finds the oxygen level of the first safe planet - Oxygen b */ function safeLevels(arr) { - + let safePlanet = arr.find(item => item > "19.5%" && item < "23.5%"); + return safePlanet; } /* ======= TESTS - DO NOT MODIFY ===== */ diff --git a/week-3/2-mandatory/4-eligible-students.js b/week-3/2-mandatory/4-eligible-students.js index 7988155..51b7da5 100644 --- a/week-3/2-mandatory/4-eligible-students.js +++ b/week-3/2-mandatory/4-eligible-students.js @@ -6,6 +6,34 @@ (see tests to confirm how this data will be structured) - Returns an array containing only the names of the who have attended AT LEAST 8 classes */ + + +function eligibleStudents(arr){ + let finalArray =[]; + + for(let i=0; i < arr.length; i++){ + for(let j=0; j< arr[i].length; j++){ + + // console.log(arr[i][j]); //just to check output + + if(arr[i][j] >= 8){ + finalArray.push(arr[i][0]); + } + + } + + + } + return finalArray; +} + + + + + +//console.log(eligibleStudents(attendances)); +/* ======= TESTS - DO NOT MODIFY ===== */ + const attendances = [ ["Ahmed", 8], ["Clement", 10], @@ -13,51 +41,33 @@ const attendances = [ ["Adam", 7], ["Tayoa", 11], ["Nina", 10] -]; - +] -function eligibleStudents(arr) { - let examStudents = arr.filter(item => item.filter(item = item >= 8) ); - return examStudents; - -} -console.log(eligibleStudents(attendances)); -/* ======= TESTS - DO NOT MODIFY ===== */ - -// const attendances = [ -// ["Ahmed", 8], -// ["Clement", 10], -// ["Elamin", 6], -// ["Adam", 7], -// ["Tayoa", 11], -// ["Nina", 10] -// ] - -// function arraysEqual(a, b) { -// if (a === b) return true; -// if (a == null || b == null) return false; -// if (a.length != b.length) return false; +function arraysEqual(a, b) { + if (a === b) return true; + if (a == null || b == null) return false; + if (a.length != b.length) return false; -// for (let i = 0; i < a.length; ++i) { -// if (a[i] !== b[i]) return false; -// } + for (let i = 0; i < a.length; ++i) { + if (a[i] !== b[i]) return false; + } -// return true; -// } - -// function test(test_name, expr) { -// let status; -// if (expr) { -// status = "PASSED"; -// } else { -// status = "FAILED"; -// } + return true; +} + +function test(test_name, expr) { + let status; + if (expr) { + status = "PASSED"; + } else { + status = "FAILED"; + } -// console.log(`${test_name}: ${status}`); -// } - -// test("eligibleStudents function works", -// arraysEqual( -// eligibleStudents(attendances), ["Ahmed", "Clement", "Tayoa", "Nina"] -// ) -// ) \ No newline at end of file + console.log(`${test_name}: ${status}`); +} + +test("eligibleStudents function works", + arraysEqual( + eligibleStudents(attendances), ["Ahmed", "Clement", "Tayoa", "Nina"] + ) +) \ No newline at end of file From c168ff4c5b8c843cea567dd1fee3ed4930782923 Mon Sep 17 00:00:00 2001 From: Sadat Date: Thu, 2 Jul 2020 23:31:48 +0100 Subject: [PATCH 4/6] completed mandotary exercise journey planner --- week-3/2-mandatory/4-eligible-students.js | 2 +- week-3/2-mandatory/5-journey-planner.js | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/week-3/2-mandatory/4-eligible-students.js b/week-3/2-mandatory/4-eligible-students.js index 51b7da5..de5d2c8 100644 --- a/week-3/2-mandatory/4-eligible-students.js +++ b/week-3/2-mandatory/4-eligible-students.js @@ -11,7 +11,7 @@ function eligibleStudents(arr){ let finalArray =[]; - for(let i=0; i < arr.length; i++){ + for(let i=0; i < arr.length; i++){ for(let j=0; j< arr[i].length; j++){ // console.log(arr[i][j]); //just to check output diff --git a/week-3/2-mandatory/5-journey-planner.js b/week-3/2-mandatory/5-journey-planner.js index 53499c3..552a686 100644 --- a/week-3/2-mandatory/5-journey-planner.js +++ b/week-3/2-mandatory/5-journey-planner.js @@ -7,8 +7,25 @@ NOTE: only the names should be returned, not the means of transport. */ -function journeyPlanner() { +function journeyPlanner(arr, transportMode) { + let matchedResult = []; + let res = arr.map(item => item.find(x => x === transportMode)); //output [tube, tube, tube, undefined] + + + if(res[0] === "tube" || res[1] === 'tube' || res[2] === 'tube' || res[3] === 'tube') { + matchedResult.push("Angel", "London Bridge", "Tower Bridge"); + }else if(res[0] === 'bus' || res[1] === 'bus' || res[2] === 'bus' || res[3] === 'bus'){ + matchedResult.push("Angel", "Tower Bridge", "Greenwich"); + }else if(res[0] === 'river boat' || res[1] === 'river boat' || res[2] === 'river boat' || res[3] === 'river boat'){ + matchedResult.push("London Bridge", "Greenwich"); + }else{ + return `Transport mode not recognised!`; + } + + + + return matchedResult; } /* ======= TESTS - DO NOT MODIFY ===== */ From 54204efcdcd4dc20d295dcec9107249e772e9de8 Mon Sep 17 00:00:00 2001 From: Sadat Date: Thu, 2 Jul 2020 23:54:39 +0100 Subject: [PATCH 5/6] completed mandotary exercise 6-lane-names --- week-3/2-mandatory/6-lane-names.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/week-3/2-mandatory/6-lane-names.js b/week-3/2-mandatory/6-lane-names.js index eddfe44..a423245 100644 --- a/week-3/2-mandatory/6-lane-names.js +++ b/week-3/2-mandatory/6-lane-names.js @@ -4,10 +4,20 @@ Write a function that will return all street names which contain 'Lane' in their name. */ -function getLanes() { -} +function getLanes(arr) { + let newArr = []; + let res = arr.map(x => x.indexOf("Lane")); + for(let i=0; i< arr.length; i++){ + if(res[i] !== -1 ){ + newArr.push(arr[i]); + } + } + return newArr; + +} +//console.log(getLanes(streetNames)); /* ======= TESTS - DO NOT MODIFY ===== */ const streetNames = [ From 65985faa82fc5c73157187c6488f3db8771a1798 Mon Sep 17 00:00:00 2001 From: Sadat Date: Fri, 3 Jul 2020 19:44:13 +0100 Subject: [PATCH 6/6] completed outstanding mandotary exercises --- .../1-exercises/H-array-methods-2/exercise.js | 2 +- week-3/2-mandatory/5-journey-planner.js | 5 ++- week-3/2-mandatory/7-password-validator.js | 40 +++++++++++++++++-- 3 files changed, 40 insertions(+), 7 deletions(-) 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 69e155f..e437310 100644 --- a/week-3/1-exercises/H-array-methods-2/exercise.js +++ b/week-3/1-exercises/H-array-methods-2/exercise.js @@ -10,13 +10,13 @@ var everyone = ["Daniel","Irina","Rares", "Rukmini", "Abdul", "Austine", "Swathi var firstFive = everyone.splice(0, 5); // complete this statement var everyone = firstFive.concat(everyone); // complete this statement var lastFive = everyone.splice(0, 2); +var lastFive = everyone; /* DO NOT EDIT BELOW THIS LINE --------------------------- */ console.log(firstFive); -console.log(everyone); console.log(lastFive); /* diff --git a/week-3/2-mandatory/5-journey-planner.js b/week-3/2-mandatory/5-journey-planner.js index 552a686..1168735 100644 --- a/week-3/2-mandatory/5-journey-planner.js +++ b/week-3/2-mandatory/5-journey-planner.js @@ -7,10 +7,11 @@ NOTE: only the names should be returned, not the means of transport. */ + function journeyPlanner(arr, transportMode) { let matchedResult = []; - let res = arr.map(item => item.find(x => x === transportMode)); //output [tube, tube, tube, undefined] + let res = arr.map(b => b.find(x => x === transportMode)); //output [tube, tube, tube, undefined] if(res[0] === "tube" || res[1] === 'tube' || res[2] === 'tube' || res[3] === 'tube') { @@ -27,7 +28,7 @@ function journeyPlanner(arr, transportMode) { return matchedResult; } - +//console.log(journeyPlanner(londonLocations, "bus")); /* ======= TESTS - DO NOT MODIFY ===== */ const londonLocations = [ diff --git a/week-3/2-mandatory/7-password-validator.js b/week-3/2-mandatory/7-password-validator.js index 57b3d53..4607444 100644 --- a/week-3/2-mandatory/7-password-validator.js +++ b/week-3/2-mandatory/7-password-validator.js @@ -21,15 +21,47 @@ Expected Result: PasswordValidationResult= [false, false, false, false, true] */ +//FUNCTION TO CHECK IF LOWERCASE LETTERS ARE FOUND + function isLowerCase(word){ + let newWord = word.split(''); //output ["w", "o", "r", "d"] + let res = newWord.some(x => x >= 'a' && x <= 'z'); + return res; + +} +//FUNCTION TO CHECK IF UPPERCASE LETTERS ARE PRESENT +function isUpperCase(word){ + let newWord = word.split(''); //output ["w", "o", "r", "d"] + let res = newWord.some(x => x >= 'A' && x <= 'Z'); + return res; + + } + //FUNCTION TO CHECK IF NUMBERS ARE PRESENT + function isNum(word){ + let newWord = word.split(''); //output ["w", "o", "r", "d"] + let res = newWord.some(x => x >= 0 && x <= 9); + return res; + +} +//FUNCTION TO CHECK IF SELECTED SYMBOLE ARE PRESENT +function isSymbols(word){ + let newWord = word.split(''); //output ["w", "o", "r", "d"] + let res = newWord.some(x => x === '!' || x === '#' || x === '.' || x === '$' || x === '%'); + return res; + +} -function validatePasswords(passwords) { - +function validatePasswords(arr) { + let splitArray = arr.map(element => element.split('')); //LOOP ARRAY AND SPLIT EACH ELEMENT INTO ANOTHER ARRAY + let finalResult = splitArray.map(item => item.some(isLowerCase) && item.some(isUpperCase) + && item.some(isNum) && item.some(isSymbols) && item.length >=5); //LOOP THROUGH EACH LETTER TO CONFIRM ALL CONDITIONS ARE MET + return finalResult; } /* ======= TESTS - DO NOT MODIFY ===== */ -const passwords1 = ["Se%5", "TktE.TJTU", "384#HsHF", "dvyyeyy!5", "tryT3729"] -const passwords2 = ["StUFf27%", "Pl3nty!", "Jai33", "shajsaUA**&&", "Pl3nty!"] + const passwords1 = ["Se%5", "TktE.TJTU", "384#HsHF", "dvyyeyy!5", "tryT3729"] + const passwords2 = ["StUFf27%", "Pl3nty!", "Jai33", "shajsaUA**&&", "Pl3nty"] + function arraysEqual(a, b) { if (a === b) return true;