diff --git a/session-01/validators.js b/session-01/validators.js index 56ea66d..48be9c3 100644 --- a/session-01/validators.js +++ b/session-01/validators.js @@ -7,7 +7,15 @@ - username cannot contain special characters */ function validUsername(username) { - return; + if(username.length < 3 || username.length > 10) + return false; + if (!/^[a-zA-Z]/.test(username.charAt(0))) + return false; + + if (!/^[a-zA-Z0-9]+$/.test(username)) + return false; + + return true; } /* @@ -17,7 +25,14 @@ function validUsername(username) { - password must contain at least 1 letter, 1 number, and 1 special character */ function validPassword(password) { - return; + if(password.length < 10 || password.length > 64 ) + return false; + + let hasLetter = /[a-zA-Z]/.test(password); + let hasNumber = /[0-9]/.test(password); + let hasSpecialCharacter = /[^a-zA-Z0-9]/.test(password) + + return hasLetter && hasNumber && hasSpecialCharacter; } module.exports = { validUsername, validPassword }; diff --git a/session-02/exercise.js b/session-02/exercise.js index 6ade818..32632cf 100644 --- a/session-02/exercise.js +++ b/session-02/exercise.js @@ -3,7 +3,12 @@ For example, for the input ["cat", "hat"], return ["CAT", "HAT"] */ function transformArrayToUpper(listOfStrings) { - return; + for(let i = 0; i < listOfStrings.length; i++){ + let words = listOfStrings[i]; + listOfStrings[i] = words.toUpperCase(); + } + console.log(listOfStrings); + return listOfStrings; } /* @@ -16,7 +21,14 @@ function transformArrayToUpper(listOfStrings) { the function should return 51 */ function sumOfAllAges(listOfStudentObjects) { - return; + let sum = 0; + for(let i = 0; i < listOfStudentObjects.length; i++){ + let age = listOfStudentObjects[i].age; + if(typeof age === 'number') + sum += age; + } + console.log(sum); + return sum; } module.exports = { transformArrayToUpper, sumOfAllAges };