Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

completed session 1 hw #30

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions session-01/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,18 @@
- username cannot contain special characters
*/
function validUsername(username) {
return;
if (username.length < 3 || username.length > 10){
return false;
}
else if (username[0].match(/[a-z]/i) === null){
return false;
}
else if (username.match(/[^a-zA-Z0-9]/) !== null){
return false;
}
else {
return true;
}
}

/*
Expand All @@ -17,7 +28,21 @@ 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;
}
else if (password.match(/[a-zA-Z]/) === null){
return false;
}
else if (password.match(/[0-9]/) === null){
return false;
}
else if (password.match(/[^a-zA-Z0-9]/) === null){
return false;
}
else {
return true;
}
}

module.exports = { validUsername, validPassword };
13 changes: 11 additions & 2 deletions session-02/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
For example, for the input ["cat", "hat"], return ["CAT", "HAT"]
*/
function transformArrayToUpper(listOfStrings) {
return;
for (let i = 0; i < listOfStrings.length; i++) {
listOfStrings[i] = listOfStrings[i].toUpperCase();
}
return listOfStrings;
}

/*
Expand All @@ -16,7 +19,13 @@ function transformArrayToUpper(listOfStrings) {
the function should return 51
*/
function sumOfAllAges(listOfStudentObjects) {
return;
let sum = 0;
for (let i = 0; i < listOfStudentObjects.length; i++) {
if (listOfStudentObjects[i].age) {
sum += listOfStudentObjects[i].age;
}
}
return sum;
}

module.exports = { transformArrayToUpper, sumOfAllAges };