Skip to content

Conversation

@zanetasochon
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.

Żaneto,

Zadania wyszły bardzo dobrze! 👍
Zostawiłem Ci komentarze jak jeszcze można usprawnić Twój kod ;)

console.log('Wynik dekrementacji jest większy od 20');
} else {
console.log('Wynik dekrementacji jest mniejszy od 20');
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PS. Może warto było zapisywać dane w tablicy i potem przy pomocy pętli iterować po każdym elemencie i wykorzystać if do warunku - takie rozwiązanie może być optymalniejsze :)

02/app.js Outdated
counter++;
result = result * a;

displayString = `${displayString} * ${a}`;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jak zrobić, aby pominąć znak na samym początku? Może wystarczy if sprawdzający czy to "pierwsza" iteracja?

03/app.js Outdated
Comment on lines 19 to 29
const firstComb = (a > b && b > c) || (a < b && b > c && a > c) ? a + b : null;
const secondComb = a > b && c > b ? a + c : null;
const thirdComb = b > a && c > a ? b + c : null;

if (firstComb === null && secondComb === null) {
return thirdComb;
} else if (firstComb === null && thirdComb === null) {
return secondComb;
} else if (thirdComb === null && secondComb === null) {
return firstComb;
}
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 warto dodać liczby do tablicy i je posortować? Myślę, że będzie prościej :)

03/app.js Outdated
Comment on lines 43 to 45
const isNull = `Podany arguments ${num} nie jest liczbą`;
const isTrue = `Podany arguments ${num} jest parzysty`;
const isFalse = `Podany arguments ${num} jest nieparzysty`;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jeśli idziemy w tą stronę to można jeszcze ładniej to zrobić tj. wykorzystać strukturę danych np.

const messages = {
     'null': '...',
     'true': '...',
}

console.log(messages[bool])

Tutaj znajdziesz szczegóły: https://devmentor.pl/b/mniej-instrukcji-warunkowych

};

const biggestTen = getTenBiggest(newArr);
console.log('Średnia arytmetyczna 10 największych liczb:', biggestTen);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

05/app.js Outdated
Comment on lines 21 to 25
const initVal = 0;
const sumWithInit = grades.reduce((acc, curr) => acc + curr, initVal);
const avgSum = sumWithInit / grades.length;

return avgSum;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Zwróć uwagę, że tutaj mamy powielony kod z linii 39-43 - może warto napisać funkcję, którą wykorzystasz w obu tych miejscach.

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.

Żaneto,

Zdecydowanie teraz wygląda lepiej! 👍
Zostawiłem jeszcze kilka komentarzy do przejrzenia :)

Comment on lines 40 to 42
}

if (item < 20) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jeśli chcemy wykluczyć "równe" to lepiej zapisać else if zamiast if - bo wtedy wykona się jedno lub drugie. A teraz jedno i drugie porównanie. Z punktu widzenia optymalizacji obecne rozwiązanie jest gorsze.

Natomiast jeśli przypisać też równie to lepiej użyć jedynie else

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chciałam wypisać w konsoli zarówno listę wyników większych od 20 i listę mniejszych od 20, tak jak zakłada polecenie :)

Użyj instrukcji warunkowej, aby sprawdzić, który z wyników jest większy od 20, a który mniejszy.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I oczywiście przy użyciu else if otrzymuje to co chciałam :)

displayString = `${a}`;
} else {
displayString = `${displayString} * ${a}`;
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

const initVal = 0;
const sumWithInitVal = twoBiggest.reduce((acc, curr) => acc + curr, initVal);

return sumWithInitVal;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

};

const randomBool = bool;
const randomBool = messages[bool];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Teraz już nie potrzebujemy switch-a, rozwiązanie jest już dostępne w randomBool :)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

O, wow :o

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:)

return grades;
} else {
return allGrades;
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

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.

👍

}

if (item < 20) {
} else if (item < 20) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

};

const randomBool = bool;
const randomBool = messages[bool];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:)

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