-
Notifications
You must be signed in to change notification settings - Fork 169
tasks js-basics-arrays finished #138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "liveServer.settings.port": 5501 | ||
| } |
| 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); | ||
| 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]); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
|
|
||
|
|
||
|
|
||
|
|
||
| // nie modyfikuj kodu poniżej! | ||
|
|
@@ -18,6 +32,8 @@ function createRandomArray() { | |
| return arr; | ||
| } | ||
|
|
||
|
|
||
|
|
||
| function getRandomInteger(min, max) { | ||
| return Math.round(Math.random() * (max-min) + min); | ||
| } | ||
| 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
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
|
|
||
| //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ł | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| 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); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
| 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
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oba są prawdziwe :P
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍