-
- Notifications
You must be signed in to change notification settings - Fork 120
Labs 1-7 #23
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
MaksGovor wants to merge 11 commits into HowProgrammingWorks:master Choose a base branch from MaksGovor: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
Labs 1-7 #23
Changes from 1 commit
Commits
Show all changes
11 commits Select commit Hold shift + click to select a range
096e8ee Fix video
tshemsedinov 9442132 Merge branch 'master' of github.com:HowProgrammingWorks/Iteration
tshemsedinov 9c7edda Add nested loops task
tshemsedinov d20b5b6 Add for..in task
tshemsedinov bebe19a Add exercises description
tshemsedinov 3d19ce5 Use pop instead of shift
tshemsedinov 2c13705 Update Exercises.ru.md (#19)
ArMANIAK 1ca9ca9 Labs 1-7
MaksGovor 13cec43 Update Exercises/3-while.js
MaksGovor 6c1b03e Minor edits
MaksGovor e602368 Merge branch 'master' of https://github.com/MaksGovor/Iteration
MaksGovor 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
Labs 1-7
- Loading branch information
commit 1ca9ca9411d143d490e93f012da7ed01a8119523
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 |
|---|---|---|
| @@ -1,9 +1,10 @@ | ||
| 'use strict'; | ||
| | ||
| const sum = (...args) => { | ||
| // Use for loop and accumulator variable | ||
| // to calculate sum of all given arguments | ||
| // For example sum(1, 2, 3) should return 6 | ||
| let res = 0; | ||
| for (let i = 0; i < args.length; i++) { | ||
| res += args[i]; | ||
| } return res; | ||
| }; | ||
| | ||
| module.exports = { sum }; |
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,9 +1,10 @@ | ||
| 'use strict'; | ||
| | ||
| const sum = (...args) => { | ||
| // Use for..of loop and accumulator variable | ||
| // to calculate sum of all given arguments | ||
| // For example sum(1, 2, 3) should return 6 | ||
| let res = 0; | ||
| for (const value of args) { | ||
| res += value; | ||
| } return res; | ||
| }; | ||
| | ||
| module.exports = { sum }; |
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,9 +1,10 @@ | ||
| 'use strict'; | ||
| | ||
| const sum = (...args) => { | ||
| // Use while loop and accumulator variable | ||
| // to calculate sum of all given arguments | ||
| // For example sum(1, 2, 3) should return 6 | ||
| let result = 0; | ||
| while (args.length > 0) { | ||
| result += args.pop(); | ||
| } return result; | ||
| }; | ||
| | ||
| module.exports = { sum }; | ||
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,9 +1,12 @@ | ||
| 'use strict'; | ||
| | ||
| const sum = (...args) => { | ||
| // Use do..while loop and accumulator variable | ||
| // to calculate sum of all given arguments | ||
| // For example sum(1, 2, 3) should return 6 | ||
| if (args.length === 0) return 0; | ||
| let result = 0; | ||
| do { | ||
| result += args.pop(); | ||
| } while (args.length > 0); | ||
| return result; | ||
| }; | ||
| | ||
| module.exports = { sum }; |
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,8 +1,5 @@ | ||
| 'use strict'; | ||
| | ||
| const sum = (...args) => 0; | ||
| // Use Array.prototype.reduce method | ||
| // to calculate sum of all given arguments | ||
| // For example sum(1, 2, 3) should return 6 | ||
| const sum = (...args) => args.reduce(((acc, cur) => acc + cur), 0); | ||
| | ||
| module.exports = { sum }; |
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,9 +1,32 @@ | ||
| 'use strict'; | ||
| | ||
| const max = matrix => { | ||
| // Use nested for loop to find max value in 2d matrix | ||
| // For example max([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) | ||
| // should return 9 | ||
| let value = matrix[0][0]; | ||
| for (const index in matrix) { | ||
| const line = matrix[index]; | ||
| for (const index2 in line) { | ||
| const colum = line[index2]; | ||
| if (colum > value) value = colum; | ||
| } | ||
| } | ||
| return value; | ||
| }; | ||
| | ||
| /*const max = matrix => { | ||
| let value = matrix[0][0]; | ||
| for (const arr of matrix) { | ||
| for (const i of arr) { | ||
| if (i > value) value = i; | ||
| } | ||
| } | ||
| return value; | ||
| };*/ | ||
| | ||
| /*const max = matrix => { | ||
| const modeMatrix = matrix | ||
| .map(arr => arr.reduce((a, b) => (a > b ? a : b))) | ||
| .reduce((a, b) => (a > b ? a : b)); | ||
| return modeMatrix; | ||
| };*/ | ||
| | ||
| module.exports = { max }; |
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,19 +1,12 @@ | ||
| 'use strict'; | ||
| | ||
| const ages = persons => { | ||
| // Use for..in to calculate age for each person | ||
| // For example ages({ | ||
| // lenin: { born: 1870, died: 1924 }, | ||
| // mao: { born: 1893, died: 1976 }, | ||
| // gandhi: { born: 1869, died: 1948 }, | ||
| // hirohito: { born: 1901, died: 1989 }, | ||
| // }) | ||
| // should return { | ||
| // lenin: 54, | ||
| // mao: 83, | ||
| // gandhi: 79, | ||
| // hirohito: 88, | ||
| // } | ||
| const age = {}; | ||
| for (const key in persons) { | ||
| const person = persons[key]; | ||
| age[key] = person.died - person.born; | ||
| } | ||
| return age; | ||
| }; | ||
| | ||
| module.exports = { ages }; |
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.
Uh oh!
There was an error while loading. Please reload this page.