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
6 changes: 6 additions & 0 deletions 01/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const users = ['Jan Kowalski', 'Monika Wysocka', 'Adam Nowak', 'Michał Ozimek', 'Dorota Rudzińska', 'Agata Borsuk'];

console.log(users[0]);
console.log(users[2]);
console.log(users[4]);
console.log('Liczba elementów tablicy:', 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.

👍

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

// wyświetlenie w konsoli wszystkich elementów tablicy przy pomocy pętli for

for (let i = 0; i < randomArray.length; i++) {
console.log(randomArray[i]);
}

// wyświetlenie w konsoli wszystkich elementów tablicy przy pomocy metody tablicowej .forEach()

randomArray.forEach(el => console.log(el));

// wyświetl wartość 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 @@ -9,15 +23,15 @@ console.log(randomArray);
// ponieważ w JS występuje mechanizm tzw. hoisting-u

function createRandomArray() {
const arr = [];
const len = getRandomInteger(1, 10)
for(let i=0; i<len; i++) {
arr.push( getRandomInteger(1, 100) );
}
const arr = [];
const len = getRandomInteger(1, 10);
for (let i = 0; i < len; i++) {
arr.push(getRandomInteger(1, 100));
}

return arr;
return arr;
}

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

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

console.log(oddNumbers);
console.log('długość tablicy:', oddNumbers.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.

👍

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

const currYear = new Date().getFullYear();

const newArr = years.map(year => currYear - year);

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

👍

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

const evenSum = numbers.filter(num => num % 2 === 0).reduce((acc, curr) => acc + curr, 0);

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

👍