-
Notifications
You must be signed in to change notification settings - Fork 169
Complete tasks from JS arrays #145
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
Open
Katalia91
wants to merge
12
commits into
devmentor-pl:master
Choose a base branch
from
Katalia91:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
20c67e9
JS arrays: complete task 01
Katalia91 5dd2356
JS arrays: complete task 02
Katalia91 94ffda2
JS arrays: complete task 03
Katalia91 7e6de52
JS arrays: complete task 04
Katalia91 a2d5eb1
JS arrays: complete task 05
Katalia91 e3adfd5
JS arrays task 05: wrap code in function declaration
Katalia91 af4fc19
JS arrays task 05: make function flexible
Katalia91 8c9e3e7
JS arrays task 05: refactor the code and change function into arrow f…
Katalia91 72fd7cc
JS arrays task 05: rename variables
Katalia91 8d490b6
Task 03: fix bug with global variable
Katalia91 666023c
Task 04: Refactor the code
Katalia91 05d5f79
Task 05: refactor the code
Katalia91 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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}`); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
|
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. 👍 |
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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++) { | ||
|
Katalia91 marked this conversation as resolved.
|
||
| if (i % 2 === 0) { | ||
| oddNumbers.push(i); | ||
| } | ||
| } | ||
| console.log(oddNumbers); | ||
| } | ||
| addOddNumbers(0); | ||
| addOddNumbers(1); | ||
| addOddNumbers(2); | ||
| addOddNumbers(100); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
|
Katalia91 marked this conversation as resolved.
|
||
| }); | ||
| console.log(passedYears); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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])); | ||
|
Katalia91 marked this conversation as resolved.
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
👍