Skip to content

Conversation

@kacpermak1
Copy link

No description provided.

Copy link
Owner

@devmentor-pl devmentor-pl left a 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 = [
Copy link
Owner

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)) {
Copy link
Owner

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 */
Copy link
Owner

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);
Copy link
Owner

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);
Copy link
Owner

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 {
Copy link
Owner

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, '_')
}
Copy link
Owner

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;
}
Copy link
Owner

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);
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants