Closed mserykh closed 3 years ago
let allStudents = [
'A',
'B-',
1,
4,
5,
2
]
let studentsWhoPass = [];
for (let i = 0; i < allStudents.length; i++) {
if (allStudents[i] >= 3 || allStudents[i] === 'A' || allStudents[i] === 'A-' || allStudents[i] === 'B' || allStudents[i] === 'B-') {
studentsWhoPass.push(allStudents[i]);
}
}
console.log(studentsWhoPass);
@dev-experience please note that initial array has missing ,
:
let allStudents = [
'A',
'B-'
1,
4
5,
2
]
@dev-experience please note that initial array has missing
,
:let allStudents = [ 'A', 'B-' 1, 4 5, 2 ]
@mserykh could you please fix it via a pull request?
@mserykh please check my comments in the code.
// What is the reason for `let`?
let allStudents = [
'A',
'B-',
1,
4,
5,
2
] // No semicolon
// What happened with the indentation?
let studentsWhoPass = [];
// Is there reason for `let`?
for (let i = 0; i < allStudents.length; i++) {
// Please be aware that `>=` doesn't check data types
// Do you mind extracting the check to a function for cleaner code?
if (allStudents[i] >= 3 || allStudents[i] === 'A' || allStudents[i] === 'A-' || allStudents[i] === 'B' || allStudents[i] === 'B-') {
// Conceptual question: how the result of `[A, B-, 1, 4, 5]` tells you which particular student pass which don't?
studentsWhoPass.push(allStudents[i]);
}
}
console.log(studentsWhoPass);
@dev-experience please note that initial array has missing
,
:let allStudents = [ 'A', 'B-' 1, 4 5, 2 ]
@mserykh could you please fix it via a pull request? @dev-experience please see a PR
const allStudents = ["A", "B-", 1, 4, 5, 2];
const isPass = mark => mark >= 3 || mark === "A" || mark === "A-" || mark === "B" || mark === "B-";
const findStudentsWhoPass = marks => {
const result = [];
for (let i = 0; i < marks.length; i++) {
const currentStudent = i;
const curentMark = marks[i];
if (isPass(curentMark)) {
result.push(currentStudent);
}
}
return result
};
const studentsWhoPass = findStudentsWhoPass(allStudents);
console.log(studentsWhoPass);
Hey @dev-experience, thank you a lot for your support and explanations you provided to me to solve this one! More then appreciated.
@mserykh looks great! Clean and readable 👍
Assignment
Operators
Instructions
Play around with operators. Here's a suggestion for a program you can implement:
You have a set of students from two different grading systems.
First grading system
One grading system is defined as grades being from 1-5 where 3 and above means you pass the course.
Second grading system
The other grade system has the following grades
A, A-, B, B-, C, C-
whereA
is the top grade andC
is the lowest passing grade.The task
Given the following array
allStudents
representing all students and their grades, construct a new arraystudentsWhoPass
containing all students who pass.Rubric