Skip to content

Commit

Permalink
clean code final version
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahmoud159 committed Sep 5, 2023
1 parent 2e6da53 commit 64e7e7a
Showing 1 changed file with 81 additions and 0 deletions.
81 changes: 81 additions & 0 deletions lean_Code_Ensit_MW/FixMePlease.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,63 @@ function imafunction(a1: Number, a2: Number, a3: Number): boolean {
return a2 <= a1 && a1 <= a3;
}

Answer :
function high_less(a1,a2,a3:Number): boolean {

This comment has been minimized.

Copy link
@Abdelkader-Degachi

Abdelkader-Degachi Sep 11, 2023

Owner

Still a1, a2, a3 are not meaningful names.

return a2 <= a1 && a1 <= a3;
}

//Q2: We want to have student type with some information. (If it's not pronounceable how you will say it)
type DtaRcrd102 = {
xvcnxjv: String;
hfdsjlfh: String;
ghdkfkkk: number;
}

Answer :
type Student = {
firstname: String;

This comment has been minimized.

Copy link
@Abdelkader-Degachi

Abdelkader-Degachi Sep 11, 2023

Owner

First letter of second word needs to be an uppercase.

lastname: String;
id: number;
}

//Q3: What we should call our function that return User?
getUserData();
getUser();
getUserInformation();

Answer : getUser();

This comment has been minimized.

Copy link
@Abdelkader-Degachi

Abdelkader-Degachi Sep 11, 2023

Owner

Perfect


//Q4: We want to check if that our student yearly grade is acceptable for any country Education System (in Tunisia <20, in USA 100)
isGradeBelowMax(grade, 20)

Answer :
function isGradeBelowMax(grade, country_grade)

This comment has been minimized.

Copy link
@Abdelkader-Degachi

Abdelkader-Degachi Sep 11, 2023

Owner

We want to pass always 20 but we want to define it so if someone from USA works in the project he can get the idea that 20 is the maximum. (hint const)

{
if (grade <= country_grade)
return true ;
else
return false ;
}

//Q5: I know you got the idea of variable names but I want it to be clear for anyone around the world.
Student s = new Student();
Grade g = new Grade();
Professor p = new Professor();

Answer :
Student student_1 = new Student();
Grade grade_1 = new Grade();
Professor professor_1 = new Professor();

//Q6: Don't you think we are overdoing it???
Type Student {
studentFirstName: String;
studentLastName: String;
StudentId: Number;
}

Answer : It's similar than the 3rd question

This comment has been minimized.

Copy link
@Abdelkader-Degachi

Abdelkader-Degachi Sep 11, 2023

Owner

Do you think it make sense to get first name by calling student.studentFirstName


//Q7: What we can do to avoid giving unappropriat gender value? (Hint enum)
Type Student {
firstName: String;
Expand All @@ -50,16 +80,39 @@ switch (student.gender) {
console.log("ERROR 404");
}
}
Answer :

function displayName(student: Student){
if (student.gender == "Male")
console.log("Mr." + student.firstName + " " + student.lastName);
else if (student.gender == "Female")
console.log("Mrs." + student.firstName + " " + student.lastName);
else
console.log("ERROR 404");
}


//Q8: Is it good idea to display all these arguments in one line like this?
displayUserDetails(firstName: String, lastName: String, id: Number, department: String, university: String){
// Some logic happens here
}

Answer :
function displayUserDetails (user : User)

This comment has been minimized.

Copy link
@Abdelkader-Degachi

Abdelkader-Degachi Sep 11, 2023

Owner

Good answer but sometimes we have multiple parameter and we can't escape that so the solution will be displaying each one in a seperate line.

{
console.log (user.firstName + " " + user.lastName + " " + user.id + " " + user.department + " " + user.university);
}

//Q9: Is it good idea to give all these arguments to one function?
displayUserDetails(firstName: String, lastName: String, id: Number, department: String, university: String){
}

Answer : No we can give the user in the argument
function displayUserDetails (user : User)
{
console.log (user.firstName + " " + user.lastName + " " + user.id + " " + user.department + " " + user.university);
}

//Q10: Who wants to have a function that do multiple things with multiple comments?
function evaluateStudents(studentsList) {
let passedStudents = []; // This will be filled with list of passed students
Expand All @@ -84,4 +137,32 @@ function evaluateStudents(studentsList) {
return passedStudents;
}

Answer :

This comment has been minimized.

Copy link
@Abdelkader-Degachi

Abdelkader-Degachi Sep 11, 2023

Owner

Perfect

function SucceessStudents(studentsList) {
let passedStudents = [];
const MINIMUM_GRADE_TO_PASS = 10;
studentsList.forEach((student) => {
if (student.score >= MINIMUM_GRADE_TO_PASS) {
passedStudents.push(student);
}
}
return passedStudents;
}

function SuspendedStudents(studentsList) {
studentsList.forEach((student) => {
if (student.score < MINIMUM_GRADE_TO_PASS && student.failedBefore) {
console.log(
student.gender === Gender.Male
? `Sorry Mr. ${student.name}, you are suspended.`
: `Sorry Mrs. ${student.name}, you are suspended.`
);
}
}

function FailedStudents(studentsList) {
studentsList.forEach((student) => {
if (student.score < MINIMUM_GRADE_TO_PASS && student.failedBefore = false) {
student.failedBefore = true;
}
}

0 comments on commit 64e7e7a

Please sign in to comment.