Skip to content
11 changes: 11 additions & 0 deletions 01/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const users = [
"Anna Kowalska",
"Patrycja Markowska",
"Kuba Sienkiewicz",
"Mikołaj Kopernik",
"Wisława Szymborska",
];
console.log(
`Pierwszy użytkownik: ${users[0]}, Drugi użytkownik: ${users[2]}, Trzeci użytkownik: ${users[4]}`
);
console.log(`Długość 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.

👍

27 changes: 17 additions & 10 deletions 02/app.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
const randomArray = createRandomArray();
console.log(randomArray);
for (let i = 0; i < randomArray.length; i++) {
console.log(`Result of for loop: ${randomArray[i]}`);
}



randomArray.forEach(function (el) {
console.log(`Result of forEach: ${el}`);
});
console.log(
`Last element of Random Array: ${randomArray[randomArray.length - 1]}`
);
// nie modyfikuj kodu poniżej!

// funkcję może deklarować poniżej wywołania
// 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);
}
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.

👍

15 changes: 13 additions & 2 deletions 03/app.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
const n = 24;
const oddNumbers = [];
function addOddNumbers(n) {
const oddNumbers = [];
for (let i = 1; i <= n; i++) {
Comment thread
Katalia91 marked this conversation as resolved.
if (i % 2 === 0) {
oddNumbers.push(i);
}
}
console.log(oddNumbers);
}
addOddNumbers(0);
addOddNumbers(1);
addOddNumbers(2);
addOddNumbers(100);
7 changes: 6 additions & 1 deletion 04/app.js
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
const years = [1980, 1934, 2002, 2019];
const years = [1980, 1934, 2002, 2019];

const passedYears = years.map(function (el) {
return 2025 - el;
Comment thread
Katalia91 marked this conversation as resolved.
});
console.log(passedYears);
8 changes: 7 additions & 1 deletion 05/app.js
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
const numbers = [1, 2, 3, 4, 5, 6, 7];
const sumEvenNumbers = (arr) => {
const evenNumbersSum = arr
.filter((num) => num % 2 === 0)
.reduce((sum, el) => sum + el, 0);
return evenNumbersSum;
};
console.log(sumEvenNumbers([1, 2, 3]));
Comment thread
Katalia91 marked this conversation as resolved.