-
Notifications
You must be signed in to change notification settings - Fork 206
Practice JS tasks completed #159
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
base: master
Are you sure you want to change the base?
Conversation
devmentor-pl
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kacprze,
Zadanka są ok 👍
Zostawiłem parę komentarzy "koncepcyjnych" tj. jak można by było jeszcze więcej wyciągnąć z kodu :)
| // console.log("Exponentiation: ", exponentiation); | ||
|
|
||
| // 3. Check which result is greater than 20, which is less than 20 and which is equal to 20 | ||
| const results = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Zastanawiam się czy nie lepiej byłoby zrobić z tego funkcję, która przyjmuje przez parametr nazwy oraz funkcji z działaniem. Natomiast 2 parametry to coś stałego, co potem można przekazać. Może dałoby się do tego wykorzystać wzorzec obserwator: https://refactoring.guru/pl/design-patterns/observer
| const input = prompt('Enter the multiplication factor: '); | ||
| const x = Number(input); | ||
|
|
||
| if (isNaN(x)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lepiej zdefiniować funkcję, która sprawdza poprawność danych - wtedy tych if-ów jest mniej i kod jest czytelniejszy.
PS. Może w samej funkcji tych if-ów jest mniej, ale do jej zawartości nie zaglądamy czytając kod - wystarczy jej nazwa, aby sie zorientować o co chodzi.
if(isCorrect()) {
// operacja
} else {
// komunikat
}
| } | ||
|
|
||
| /* rozwiązanie z pętlą while */ No newline at end of file | ||
| /* rozwiązanie z pętlą while */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wiem, że w zadaniu nie było napisane, ale zdecydowanie ten kod można podzielić na funkcje.
| b = parseInt(b, 10); | ||
| c = parseInt(c, 10); | ||
|
|
||
| return a + b + c - Math.min(a, b, c); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ooo super rozwiązanie! Sam był użył sort() i wybrał 2 największe ;P
| const getLargest = arr => { | ||
| if (!Array.isArray(arr) || arr.length === 0) return null; | ||
|
|
||
| return [...arr].sort((a, b) => b - a).slice(0, 10); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
super, że utworzyłeś kopie!
| @@ -0,0 +1,61 @@ | |||
| class Student { | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rozumiem, że konstruktory to zaszłość, ale w zadaniu byłą mowa o nich to lepiej się trzymać treści zadania (nie chodzi o mnie, ale o potencjalną rekrutację)
| // Static method to normalize subject names | ||
| static normalizeSubject(subject) { | ||
| return subject.trim().toLowerCase() //this could be adjusted further if we decide to handle spaces in subject names differently, perhaps by adding: .replace(/\s+/g, '_') | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
| const sum = arr.reduce((acc, num) => acc + num, 0); | ||
|
|
||
| return sum / arr.length; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
| throw new Error('Grade must be a valid number'); | ||
| } | ||
|
|
||
| const subjectKey = Student.normalizeSubject(subject); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Może zamiast pamiętać za każdym razem, aby "normalizować" subject, to napisać metodę getGradesBySubject() i tam wykonywać odpowiedniego sprawdzenia + normalizacji itp. - łatwiej będzie utrzymać porządek.
No description provided.