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

Christopher Budhram | Passes all 20 test cases #7

Closed
wants to merge 7 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
77 changes: 73 additions & 4 deletions session-01/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,37 @@
- username may contain numbers and letters
- username cannot contain special characters
*/
function validUsername(username) {
return;
function validUsername(username){

// Capturing name length
let nameLength = username.length;

// Checking to see if the name is correct in length.
if (nameLength < 3 || nameLength > 10) {
return false;
}

// Checking to see if it begins with a letter, as well as number declaration
const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
const numbers = "1234567890";
const specialCharacters = "!@#$%^&*(),./?[];:`~|";

// comparison between to see if it is a leter
for (let i = 0; i < username.length; i++){
const char = username.charAt(i);

// Check if the first character is a letter
if (i === 0 && !alphabet.includes(char)) {
return false;
}

// Checking to see if the name has numbers are no special characters
if (!numbers.includes(char) && specialCharacters.includes(char)){
return false;
}
}

return true;
}

/*
Expand All @@ -16,8 +45,48 @@ function validUsername(username) {
- 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) {
return;
function validPassword(password){

let passwordLength = password.length;

// Checking to see if the password is long enough
if (passwordLength < 10 || passwordLength > 64){
return false;
}

// creating const variables
const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
const numbers = "1234567890";
const specialCharacters = "!@#$%^&*(),./?[];:`~|";

// should return true for passwords w/ 1 letter, 1 number, and 1 special character
// these are a true of false trip bascially
let Check1 = false;
let Check2 = false;
let Check3 = false;

for (let i = 0; i < password.length; i++){
const char = password.charAt(i);

if (alphabet.includes(char)) {
Check1 = true;
}

if (numbers.includes(char)){
Check2 = true;
}

if (specialCharacters.includes(char)){
Check3 = true;
}
}


// if all 3 checks are positive, then the password is accepted
if (!Check1 || !Check2 || !Check3){
return false;
}
return true;
}

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

// iterate through the inital array, and convert every element to uppercase
for (const index of listOfStrings){
uppercaseStrings.push(index.toUpperCase());
}

// return the converted array
return uppercaseStrings;
}

/*
Expand All @@ -16,7 +25,16 @@ function transformArrayToUpper(listOfStrings) {
the function should return 51
*/
function sumOfAllAges(listOfStudentObjects) {
return;
//Initalize the empty age variable
let totalAge = 0;

//for every entry, add that age to the total age;
for (const index of listOfStudentObjects){
if (index.age) totalAge += index.age;
}

//Return the total age
return totalAge;
}

module.exports = { transformArrayToUpper, sumOfAllAges };