-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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.
Sorry, something went wrong. |
||
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.
Sorry, something went wrong. |
||
lastname: String; | ||
id: number; | ||
} | ||
|
||
//Q3: What we should call our function that return User? | ||
getUserData(); | ||
getUser(); | ||
getUserInformation(); | ||
|
||
Answer : getUser(); | ||
This comment has been minimized.
Sorry, something went wrong. |
||
|
||
//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.
Sorry, something went wrong.
Abdelkader-Degachi
Owner
|
||
{ | ||
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.
Sorry, something went wrong.
Abdelkader-Degachi
Owner
|
||
|
||
//Q7: What we can do to avoid giving unappropriat gender value? (Hint enum) | ||
Type Student { | ||
firstName: String; | ||
|
@@ -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.
Sorry, something went wrong.
Abdelkader-Degachi
Owner
|
||
{ | ||
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 | ||
|
@@ -84,4 +137,32 @@ function evaluateStudents(studentsList) { | |
return passedStudents; | ||
} | ||
|
||
Answer : | ||
This comment has been minimized.
Sorry, something went wrong. |
||
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; | ||
} | ||
} |
Still a1, a2, a3 are not meaningful names.