Skip to content

tasks js-basics-arrays finished#138

Open
code-mike-code wants to merge 5 commits intodevmentor-pl:masterfrom
code-mike-code:master
Open

tasks js-basics-arrays finished#138
code-mike-code wants to merge 5 commits intodevmentor-pl:masterfrom
code-mike-code:master

Conversation

@code-mike-code
Copy link
Copy Markdown

Zadanie 05 z .reduce() było chyba najtrudniejsze — tu dużo pomogła mi dokumentacja na mdm, aczkolwiek nadal nie do końca rozumiem zasadę działania tej metody
trochę problemów sprawiły mi tez złe nawiasy, czy średnik w złym miejscu, teraz zaczyna do mnie docierać jak problematyczne mogą być takie malutkie błędy

Copy link
Copy Markdown
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.

Michale,

Ostatecznie zadanka wyglądają bardzo dobrze (mimo problemów - one są częścią nauki) 👍

Zostawiłem też parę komentarzy odpowiadających i uzupełniających :)

Comment thread 01/app.js
@@ -0,0 +1,3 @@
const users = ['Jan Kowalski', 'Kasia Kowalska', 'Anna Janowska', 'Michał Janowski', 'Piotr Piotrowski'];

console.log(users[0], users[2], users[4], users.length); No newline at end of file
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

👍

Comment thread 02/app.js
});

// wyswietlanie ostatniego elementu tablicy
console.log(randomArray[randomArray.length -1]);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

👍

Comment thread 03/app.js
Comment on lines +15 to +17
// przy 'n=0' miałem pustą tablicę []
// prz 'n=1' miałem [1]
// przy 'n=100' miałem liczby nieparzyste o 1 do 99
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Jeśli sprawdzisz tylko 1 przypadek to nie masz pewności czy zadanie działa czy nie np. zawsze dodajesz do tablicy liczbę 1, jeśli sprawdzisz czy zadanie działa dla 1 to tak będzie, ale jak już sprawdzisz przy n=2 to tak nie będzie.
Jeśli sprawdzisz najmniejszą, największą (lub tutaj dużą) i coś po środku to jest większe prawdopodobieństwo że działa dla wszystkich liczb :)

Comment thread 03/app.js
// prz 'n=1' miałem [1]
// przy 'n=100' miałem liczby nieparzyste o 1 do 99

//plus przy .push wstawiłem nawiasy kwadratowe za pierwszym razem i nie ukrywam, że było to dla mnie problemem bo nie wiedziałem gdzie jest bład, a vsc nic nie podświetlał No newline at end of file
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Chyba jednak musiał coś podkreślać na czerwono - u mnie tak jest, sprawdziłem :P

Comment thread 04/app.js
return currentYear - year;
});

console.log(yearsPassed); No newline at end of file
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

👍

Comment thread 05/app.js
Comment on lines +14 to +16
// jesli dobrze to rozumiem to .reduce() dodaje do siebie wszystkie elementy tablicy i zwraca je jako jedną wartość??

// czy raczej dodaje wszystkie elementy tablicy do pierwszego elementu (accumulator)?? No newline at end of file
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Oba są prawdziwe :P

reduce działa tak, że to co w return wpada do pierwszego parametru i operacja jest wykonywana aż do przejścia po każdym elemencie tablicy, który jest w drugim parametrze. Warto zapisać trochę inaczej reduce tj. dodać 0 jako pierwszy element w sum - wtedy pewnie będzie to czytelniejsze jak wyświetlimy zawartość parametrów tj.

.reduce(function(sum, number) {
    console.log(sum, number);
    return sum + number;
}, 0);

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