Skip to content
Open
Show file tree
Hide file tree
Changes from 5 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
4 changes: 4 additions & 0 deletions 01/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const users = ['Janusz Kowalski', 'Robert Lewandowski', 'Jan Pawel', 'Edzia Gorniak', 'Marcin Najman'];

console.log(users[0], users[2], users[4]);
console.log(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.

👍

18 changes: 17 additions & 1 deletion 02/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,20 @@ function createRandomArray() {

function getRandomInteger(min, max) {
return Math.round(Math.random() * (max-min) + min);
}
}


// function showArrayElement(arr){
// for (let i=0; i < arr.length; i++){
// console.log(arr[i]);
// }
// }

// showArrayElement(randomArray);

function showArrayElement(arr){
arr.forEach((element) => console.log(element));
console.log(` Ostatni element tablicy to: ${arr[arr.length - 1]}`);
}

showArrayElement(randomArray);
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.

👍

22 changes: 21 additions & 1 deletion 03/app.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,22 @@
const n = 24;
const oddNumbers = [];
const oddNumbers = [];

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

function showOddNumbers(maxValue){
let arr = [];

for (let i = 0; i < maxValue; i++){
if(i%2 !== 0) {
arr.push(i);
}
}
console.log(arr);
}

showOddNumbers(n);
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 currentDate = new Date();
const currentYear = currentDate.getFullYear();

const yearsToDate = years.map((element) => currentYear - element);
console.log(yearsToDate);
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.

👍

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

// const sum = numbers.reduce((acc, el) => {
// if(el%2===0){
// return acc+el;
// }
// return acc;
// }, 0);


// console.log(sum);


const evenNumbers = numbers.filter((element) => element%2===0);
const sum = evenNumbers.reduce((acc, el) => acc+ el);
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.

Tutaj na wszelki wypadek warto dodać drugi parametr tj. evenNumbers.reduce((acc, el) => acc+ el, 0);, aby nie było błędu jak będzie pusta tablica.

console.log(sum);