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
19 changes: 19 additions & 0 deletions 01/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const users = [
"Alex Carter",
"Jamie Reynolds",
"Morgan Hayes",
"Taylor Benson",
"Riley Sutton",
"Casey Mitchell",
"Jordan Fletcher",
"Avery Collins",
"Cameron Lawson",
"Dakota Pierce",
];
console.log(`
1st name: ${users[0]}
3th name: ${users[2]}
5th name: ${users[4]}
Users array: ${users}
Array length: ${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: 19 additions & 8 deletions 02/app.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,34 @@
const randomArray = createRandomArray();
console.log(randomArray);

for (let i = 0; i < randomArray.length; i++) {
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.

Super, że jest poprawa ;P

console.log(`Index ${i}: ${randomArray[i]}`);
}

console.log("\n");

randomArray.forEach(function (num, index) {
console.log(`Index ${index}: ${num}`);
});

console.log("\n");

console.log(`Last element: ${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);
}
18 changes: 17 additions & 1 deletion 03/app.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,18 @@
const n = 24;
const oddNumbers = [];

getOddNumbers(n);
getOddNumbers(0);
getOddNumbers(1);
getOddNumbers(100);

function getOddNumbers(n) {
const oddNumbers = [];
let counter = 0;
while (n > counter) {
counter++;
if (counter % 2 == 1) {
oddNumbers.push(counter);
}
}
console.log(`n=${n} => ${oddNumbers}`);
}
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 yearsPasst = years.map(function (year) {
return new Date().getFullYear() - year;
});

console.log(yearsPasst);
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 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 numbers = [1, 2, 3, 4, 5, 6, 7];

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

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

👍