Complete tasks from JS arrays#145
Conversation
devmentor-pl
left a comment
There was a problem hiding this comment.
Natalio,
Bardzo dobrze sobie poradziłaś 👍
Zostawiłem parę komentarzy, ale nie wiem czy to były przeoczenia czy po prostu do tak "prostych" chciałaś przetestować innej podejście ;)
| console.log( | ||
| `Pierwszy użytkownik: ${users[0]}, Drugi użytkownik: ${users[2]}, Trzeci użytkownik: ${users[4]}` | ||
| ); | ||
| console.log(`Długość tablicy: ${users.length}`); |
| return Math.round(Math.random() * (max-min) + min); | ||
| } No newline at end of file | ||
| return Math.round(Math.random() * (max - min) + min); | ||
| } |
| const oddNumbers = []; No newline at end of file | ||
| function addOddNumbers(n) { | ||
| const oddNumbers = []; | ||
| for (i = 1; i <= n; i++) { |
There was a problem hiding this comment.
Uwaga na deklaracje zmiennej, jeśli przed i nie wstawisz let to i staje się zmienną globalną czego nie chcemy :)
There was a problem hiding this comment.
@devmentor-pl przeoczenie, powinnam była jeszcze raz to sprawdzić przed zrobieniem pull requesta ;) Poprawione.
| const years = [1980, 1934, 2002, 2019]; | ||
|
|
||
| const passedYears = years.map(function (el, index) { | ||
| return 2025 - years[index]; |
There was a problem hiding this comment.
Wydaje mi się lepszym rozwiązanie wykorzystać od razu el czyli return 2025 - el - wtedy nie trzeba też pisać drugiego parametru ;)
| const evenNumbersSum = arr | ||
| .filter((num) => num % 2 === 0) | ||
| .reduce((sum, el) => sum + el, 0); | ||
| console.log(evenNumbersSum); |
There was a problem hiding this comment.
Lepiej byłoby zrobić return evenNumbersSum, a console.log zrobić poniżej. Wtedy taka funkcja jest reużywalna ;)
There was a problem hiding this comment.
@devmentor-pl poprawiłam, chociaż nie jestem pewna czy to o to chodzilo?
devmentor-pl
left a comment
There was a problem hiding this comment.
Natalio,
Super, o to chodziło! 👍
No description provided.