Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"liveServer.settings.port": 5501
}
3 changes: 3 additions & 0 deletions 01/app.js
Original file line number Diff line number Diff line change
@@ -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);
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.

👍

16 changes: 16 additions & 0 deletions 02/app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
const randomArray = createRandomArray();
console.log(randomArray);

// wyswietlanie za pomoca pętli for
for(let i=0; i<randomArray.length; i++) {
console.log(randomArray[i]);
}

// wyświetlanie za pomocą metody forEach
randomArray.forEach(function(element) {
console.log(element);
});

// 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.

👍





// nie modyfikuj kodu poniżej!
Expand All @@ -18,6 +32,8 @@ function createRandomArray() {
return arr;
}



function getRandomInteger(min, max) {
return Math.round(Math.random() * (max-min) + min);
}
19 changes: 18 additions & 1 deletion 03/app.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,19 @@
const n = 24;
const oddNumbers = [];
const oddNumbers = [];

for(let i=1; i<=n; i++) {
if(i % 2 !== 0) {
oddNumbers.push(i);
}
}

console.log(oddNumbers);


// nie do końca rozumiem o co chodzi z tym sprawdzaniem warunków brzegowych

// przy 'n=0' miałem pustą tablicę []
// prz 'n=1' miałem [1]
// przy 'n=100' miałem liczby nieparzyste o 1 do 99
Comment on lines +15 to +17
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 :)


//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ł
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

11 changes: 10 additions & 1 deletion 04/app.js
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
const years = [1980, 1934, 2002, 2019];
const years = [1980, 1934, 2002, 2019];

const currentYear = new Date().getFullYear();
console.log(currentYear);

const yearsPassed = years.map(function(year) {
return currentYear - year;
});

console.log(yearsPassed);
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.

👍

17 changes: 16 additions & 1 deletion 05/app.js
Original file line number Diff line number Diff line change
@@ -1 +1,16 @@
const numbers = [1, 2, 3, 4, 5, 6, 7];
const numbers = [1, 2, 3, 4, 5, 6, 7];

const evenNumbersSum = numbers.filter(function(number) {
return number % 2 === 0;
})

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

console.log(evenNumbersSum);


// 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)??
Comment on lines +14 to +16
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);