forked from HackYourFuture/JavaScript2
-
Notifications
You must be signed in to change notification settings - Fork 0
done #2
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
annagabain
wants to merge
7
commits into
master
Choose a base branch
from
homework-week3
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
done #2
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d2d2354
2-1 for week3
annagabain c74a025
comment ex2-1
annagabain c0d39ba
Rename MY-step2-1.js to MY-step2-1-Hello_I_am_bar.js
annagabain bad3e60
ex 2-2, 2-3, 2-4, 2-5
annagabain 2e140a2
ex. 2-2, 2-3, 2-4, 2-5
annagabain ae3cc79
polished up a bit
annagabain e5d3c83
fixed
annagabain 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,19 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
| <meta http-equiv="X-UA-Compatible" content="ie=edge"> | ||
| <title>Document</title> | ||
| </head> | ||
| <body> | ||
| <script src="MY-step2-1.js"></script> | ||
| <script src="MY-step2-2-Func_with_4_Arg.js"></script> | ||
| <script src="MY-step2-3-Repeat_a_String.js"></script> | ||
| <script src="MY-step2-4-Some_practice_with_objects.js"></script> | ||
| <script src="MY-step2-5-Nest_for_loops.js"></script> | ||
| <script src="MY-step2-6-Flatten_the_Array.js"></script> | ||
| <script src="MY-step2-7-Different_Results.js"></script> | ||
| <script src="MY-step3-Base_Scope_Closures.js"></script> | ||
| </body> | ||
| </html> |
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
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,23 @@ | ||
| 'use strict'; | ||
| /*sample*/ | ||
| // function doIt() { | ||
| // console.log('I am done'); | ||
| // } | ||
| // setTimeout(doIt, 5000); | ||
|
|
||
| //Test this code by copy-pasting the whole foo and bar functions to the browser console | ||
| function foo(func) { | ||
| // What to do here? | ||
| // Replace this comment and the next line with your code | ||
| return ('Hi, I am AaaaT, who are you?'); | ||
| //console.log(func); | ||
| } | ||
|
|
||
| function bar() { | ||
| console.log('Hello, I am bar!'); | ||
| } | ||
| setTimeout(bar, 3000); | ||
| foo(bar); | ||
|
|
||
| // Do not change or remove anything below this line | ||
| module.exports = foo; | ||
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,49 @@ | ||
| 'use strict'; | ||
|
|
||
| /*2.2 You must write a function that takes 4 arguments. | ||
|
|
||
| A start value | ||
| An end value | ||
| A callback to call if the number is divisible by 3 | ||
| A callback to use if the number is divisible by 5 | ||
| The function should first generate an array containing values from start value to end value (inclusive). | ||
|
|
||
| Then the function should take the newly created array and iterate over it, and calling the first callback if the array value is divisible by 3. | ||
|
|
||
| The function should call the second callback if the array value is divisible by 5. | ||
|
|
||
| Both functions should be called if the array value is divisible by both 3 and 5. */ | ||
|
|
||
| function threeFive(startIndex, stopIndex, threeCallback, fiveCallback) { | ||
| const numbers = []; | ||
| // Replace this comment and the next line with your code | ||
| for (let i = startIndex; i <= stopIndex; i++) { | ||
| numbers.push(i); | ||
| //A callback to call if the number is divisible by 3 | ||
| if (i % 3 === 0) { | ||
| threeCallback(i); | ||
| } | ||
| //A callback to use if the number is divisible by 5 | ||
| if (i % 5 === 0) { | ||
| fiveCallback(i); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| threeFive() | ||
|
|
||
|
|
||
| function sayThree(number) { | ||
| // Replace this comment and the next line with your code | ||
| console.log(number, 'value is divisible by 3'); | ||
| } | ||
|
|
||
| function sayFive(number) { | ||
| // Replace this comment and the next line with your code | ||
| console.log(number, 'value is divisible by 5'); | ||
| } | ||
|
|
||
| threeFive(10, 15, sayThree, sayFive); | ||
|
|
||
| // Do not change or remove anything below this line | ||
| module.exports = threeFive; |
22 changes: 18 additions & 4 deletions
22
Week3/homework/step2-3.js → Week3/homework/MY-step2-3-Repeat_a_String.js
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
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
13 changes: 9 additions & 4 deletions
13
Week3/homework/step2-5.js → Week3/homework/MY-step2-5-Nest_for_loops.js
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,17 +1,22 @@ | ||
| 'use strict'; | ||
| //'use strict'; | ||
|
|
||
| function multiplyAll(arr) { | ||
| // eslint-disable-next-line | ||
| let product = 1; | ||
|
|
||
| // Replace this comment and the next line with your code | ||
| for(let i=0; i < arr.length; i++){ | ||
| for (let j=0; j < arr[i].length; j++){ | ||
| product = product * arr[i][j]; | ||
| } | ||
| } | ||
| console.log(arr, product); | ||
|
|
||
| return product; | ||
| } | ||
|
|
||
| const result = multiplyAll([[1, 2], [3, 4], [5, 6]]); | ||
| console.log(result); // 720 | ||
| const result = multiplyAll([[3, 4], [5, 6], [7, 8]]); | ||
| console.log(result); // 20160 | ||
|
|
||
| // Do not change or remove anything below this line | ||
| module.exports = multiplyAll; | ||
|
|
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,40 @@ | ||
| 'use strict'; | ||
|
|
||
| const arr2d = [[1, 2], [3, 4], [5, 6]]; | ||
| const arr3d = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]; | ||
|
|
||
| // const flattenArray2d = (arr) => arr.flat() | ||
| // const flattenArray3d = (arr) => arr.flat(2) //depth of 2 | ||
|
|
||
| // const flattenArray2d = flatten | ||
| // const flattenArray3d = flatten | ||
|
|
||
|
|
||
| function flattenArray2d(arr) { | ||
| let flattenArr2 = []; | ||
| for (let i = 0; i < arr.length; i++) { | ||
| for (let j = 0; j < arr[i].length; j++) { | ||
| flattenArr2.push(arr[i][j]) | ||
| } | ||
| } | ||
| return flattenArr2; | ||
| } | ||
|
|
||
| function flattenArray3d(arr) { | ||
| const flattenArr3 = []; | ||
| for (let i = 0; i < arr.length; i++) { | ||
| for (let j = 0; j < arr[i].length; j++) { | ||
| for (let l = 0; l < arr[i][j].length; l++) { | AE18||
| flattenArr3.push(arr[i][j][l]); | ||
| } | ||
| } | ||
| } | ||
| return flattenArr3; | ||
|
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 works, but also take a look at |
||
| } | ||
|
|
||
|
|
||
| //Do not change or remove anything below this line | ||
| module.exports = { | ||
| flattenArray2d, | ||
| flattenArray3d, | ||
| }; | ||
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
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
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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.
Same problem again. This function should take a function and invoke/call it. Not return anything.