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

HW1 #31

Closed
wants to merge 3 commits into from
Closed

HW1 #31

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
36 changes: 34 additions & 2 deletions session-01/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,20 @@
- username cannot contain special characters
*/
function validUsername(username) {
return;
//checks length
if( username.length<3 || username.length>10 )
return false;
// checks for special charcters,\w is used for letters and digit,
// having the ^ is negation and is checking the string for everything besides a letter/digit
//so if the string does contain something otherthan letter/digit, function will return false
if( /[^\w]/.test(username)) return false;

//checking first chracter is a letter
//the ^ is outside thr [], which chekcs if the first index in the string is a letter or not,
if(!/^[a-zA-z]/.test(username)) return false;


return true;
}

/*
Expand All @@ -17,7 +30,26 @@ function validUsername(username) {
- password must contain at least 1 letter, 1 number, and 1 special character
*/
function validPassword(password) {
return;
//checks length
if( password.length<=9 || password.length>=65 ) return false;

if (!/[a-zA-Z]/.test(password)) {
return false;
}

// Check if the password contains at least one number
if (!/[0-9]/.test(password)) {
return false;
}

//if(!/\w/.test(password)) return false;

// Check if the password contains at least one special character
if (!/[!@#$%^&*(),.?":{}|<>]/.test(password)) {
return false;
}

return true;
}

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


return upperCaseListOfStrings = listOfStrings.map((f) => f.toUpperCase());
}

/*
Expand All @@ -16,7 +18,29 @@ function transformArrayToUpper(listOfStrings) {
the function should return 51
*/
function sumOfAllAges(listOfStudentObjects) {
return;
let sum = 0;
// uses the typeof to determine if the property exits and is a primitive type number
// for (let i = 0; i < listOfStudentObjects.length; i++) {
// if (typeof listOfStudentObjects[i].age === "number") {
// sum += listOfStudentObjects[i].age;
// } else {
// console.log("No age for index " + i);
// }
// };

// uses the "in" opertor checking if the property is in the object if('propertyName' in ObjectName)
for (let i = 0; i < listOfStudentObjects.length; i++) {
// Check if the 'age' property exists and is a valid number
if ('age' in listOfStudentObjects[i] ) {
sum += listOfStudentObjects[i].age;
} else {
console.log("No age for index " + i);
}
}


return sum;
}


module.exports = { transformArrayToUpper, sumOfAllAges };
4 changes: 2 additions & 2 deletions session-02/loops.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ for (const fruit of fruits) {
// console.log(item);
// }

// .forEach
// .forEach, its a function that tkes in a function and applies the function to every element of the index
// function myPrint(item) {
// console.log("Delicious: ", item);
// }
Expand All @@ -40,7 +40,7 @@ console.log(result);
// callback function

// .map() // transform/convert/change

//your able to return the results into new array, store into new variable while keeping the original array unchanged
let pluralFruits = fruits.map((f) => f + "s");

console.log(pluralFruits);
Expand Down
2 changes: 1 addition & 1 deletion session-02/objects-arrays.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@ console.log(Object.keys(things)); // don't do this
fruits.push("Durian");
console.log(fruits);

// pop / shift
// pop(removes element from the back) / shift(removes element from the front)
console.log(fruits.pop(), fruits.shift());
console.log(fruits.length);