diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..28a51d5 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "compile-hero.disable-compile-files-on-did-save-code": false +} \ No newline at end of file diff --git a/session-01/dist/validators.dev.js b/session-01/dist/validators.dev.js new file mode 100644 index 0000000..9c8fe6e --- /dev/null +++ b/session-01/dist/validators.dev.js @@ -0,0 +1,32 @@ +"use strict"; + +/* + Write a function that returns true or false if the given username + is valid according to the following rules: + - username must be between (and including) 3-10 characters in length + - username must begin with a letter + - username may contain numbers and letters + - username cannot contain special characters +*/ +function validUsername(username) { + var usernamePattern = /^[a-zA-Z][a-zA-Z0-9]{2,9}$/; + return usernamePattern.test(username); +} +/* + Write a function that returns true or false if the given password + is valid according to the following rules: + - password must be between (and including) 10-64 characters in length + - password must contain at least 1 letter, 1 number, and 1 special character +*/ + + +function validPassword(password) { + var passwordPattern = /^(?=.*[a-zA-Z])(?=.*[0-9])(?=.*[!@#$%^&*(),.?":{}|<>])[a-zA-Z0-9!@#$%^&*(),.?":{}|<>]{10,64}$/; + return passwordPattern.test(password); + return; +} + +module.exports = { + validUsername: validUsername, + validPassword: validPassword +}; \ No newline at end of file diff --git a/session-01/validators.js b/session-01/validators.js index 56ea66d..9ce0f43 100644 --- a/session-01/validators.js +++ b/session-01/validators.js @@ -7,7 +7,9 @@ - username cannot contain special characters */ function validUsername(username) { - return; + const usernamePattern = /^[a-zA-Z][a-zA-Z0-9]{2,9}$/; + return usernamePattern.test(username); + } /* @@ -17,6 +19,8 @@ function validUsername(username) { - password must contain at least 1 letter, 1 number, and 1 special character */ function validPassword(password) { + const passwordPattern = /^(?=.*[a-zA-Z])(?=.*[0-9])(?=.*[!@#$%^&*(),.?":{}|<>])[a-zA-Z0-9!@#$%^&*(),.?":{}|<>]{10,64}$/; + return passwordPattern.test(password); return; } diff --git a/session-02/dist/exercise.dev.js b/session-02/dist/exercise.dev.js new file mode 100644 index 0000000..cbb71fb --- /dev/null +++ b/session-02/dist/exercise.dev.js @@ -0,0 +1,34 @@ +"use strict"; + +/* + Transform the input array of strings into uppercase strings + For example, for the input ["cat", "hat"], return ["CAT", "HAT"] +*/ +function transformArrayToUpper(listOfStrings) { + return listOfStrings.map(function (string) { + return string.toUpperCase(); + }); +} +/* + Write a function that returns the sum of all student ages. + The function will be passed an array of objects and the result + will be the sum of all ages. + - Note, not all objects will contain an age. Omit these objects. + For example, for the input: + [{ name: 'Sandra', age: 31 }, {}, { name: 'Didi', age: 20}] + the function should return 51 +*/ + + +function sumOfAllAges(listOfStudentObjects) { + return listOfStudentObjects.filter(function (student) { + return student.age && typeof student.age === 'number'; + }).reduce(function (accumulator, student) { + return accumulator + student.age; + }, 0); +} + +module.exports = { + transformArrayToUpper: transformArrayToUpper, + sumOfAllAges: sumOfAllAges +}; \ No newline at end of file diff --git a/session-02/exercise.js b/session-02/exercise.js index 6ade818..4bc8fec 100644 --- a/session-02/exercise.js +++ b/session-02/exercise.js @@ -3,9 +3,9 @@ For example, for the input ["cat", "hat"], return ["CAT", "HAT"] */ function transformArrayToUpper(listOfStrings) { - return; + + return listOfStrings.map(string => string.toUpperCase()); } - /* Write a function that returns the sum of all student ages. The function will be passed an array of objects and the result @@ -16,7 +16,9 @@ function transformArrayToUpper(listOfStrings) { the function should return 51 */ function sumOfAllAges(listOfStudentObjects) { - return; + return listOfStudentObjects + .filter(student => student.age && typeof student.age === 'number') + .reduce((accumulator, student) => accumulator + student.age, 0); } module.exports = { transformArrayToUpper, sumOfAllAges };