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

Exercise #2 #39

Closed
wants to merge 4 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
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"compile-hero.disable-compile-files-on-did-save-code": false
}
32 changes: 32 additions & 0 deletions session-01/dist/validators.dev.js
Original file line number Diff line number Diff line change
@@ -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
};
6 changes: 5 additions & 1 deletion session-01/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}

/*
Expand All @@ -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;
}

Expand Down
34 changes: 34 additions & 0 deletions session-02/dist/exercise.dev.js
Original file line number Diff line number Diff line change
@@ -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
};
8 changes: 5 additions & 3 deletions session-02/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 };