Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 33
Week3 homework#14
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?
Uh oh!
There was an error while loading. Please reload this page.
Week3 homework #14
Changes from all commits
b7d9e3dd645b0e79955f39c081d86756a965542b9766c1b93cae0024d67d07e8098ebc9e84302cc6b2f98673c7ba180a51c2ad5fa327c203b03dfbb3a47521File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +0,0 @@ | ||
| 'use strict'; | ||
| { | ||
| const bookTitles = [ | ||
| // Replace with your own book titles | ||
| 'harry_potter_chamber_secrets', | ||
| ]; | ||
| // Replace with your own code | ||
| console.log(bookTitles); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +0,0 @@ | ||
| <!-- replace this with your HTML content --> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +0,0 @@ | ||
| /* add your styling here */ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,9 @@ | ||
| 'use strict'; | ||
| function Dog() { | ||
| // add your code here | ||
| this.name = 'Fido'; | ||
| this.color = 'white and brown'; | ||
| this.numLegs = 4; | ||
| } | ||
| const hound = new Dog(); | ||
jshortz marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -4,13 +4,25 @@ const arr2d = [[1, 2], [3, 4], [5, 6]]; | ||
| const arr3d = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]; | ||
| function flattenArray2d(arr) { | ||
| // Replace this comment and the next line with your code | ||
| console.log(arr); | ||
| const newArray = []; | ||
| for (let i = 0; i < arr.length; i++) { | ||
| for (let j = 0; j < arr[i].length; j++) { | ||
| newArray.push(arr[i][j]); | ||
| } | ||
| } | ||
| return newArray.sort(); | ||
jshortz marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| } | ||
| function flattenArray3d(arr) { | ||
| // Replace this comment and the next line with your code | ||
| console.log(arr); | ||
| const arr3dim = []; | ||
| for (let i = 0; i < arr.length; i++) { | ||
| for (let j = 0; j < arr[i].length; j++) { | ||
| for (let k = 0; k < arr[i][j].length; k++) { | ||
| arr3dim.push(arr[i][j][k]); | ||
| } | ||
| } | ||
| } | ||
| return arr3dim; | ||
| } | ||
| console.log(flattenArray2d(arr2d)); // -> [1, 2, 3, 4, 5, 6] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -20,4 +20,8 @@ f2(y); | ||
| console.log(y); | ||
| // Add your explanation as a comment here | ||
| /* In the x-code, we are logging the value of x, which has not changed. If we want this code to return 10, | ||
| we need to console.log(f1(x)). In the y-code, y is an object. The properties of an object can be altered this way, | ||
| so the function changes the value of x to 10. No alteration has been done to the variable reference itself. If f2 | ||
| attempted to change the *value* of y (rather than an attribute of its object), it would yield results like the x-code. | ||
| For example, if the function is altered, val = { x: 10 }; return val;, it will return { x: 9 } */ | ||
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. I think you get it (?). Another example: vs objects... Do you see the difference? Author 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. Yep - I assume it has to do with how JS stores them in memory - when b is set to an object, it's a reference to that object, not a new object with the same details. So whenever a property of 'a' changes, 'b' will 'change' as well (because they're both just pointing to the same object). But when a = 4 and b = a, it's setting b equal to a value of 4 (not pointing to an object). So changing the value of 'a' after that doesn't change the value of 'b'. Author 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. So in the objects example, both a and b would have a value of { 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 |
|---|---|---|
| @@ -3,8 +3,10 @@ | ||
| const values = ['a', 'b', 'c', 'd', 'a', 'e', 'f', 'c']; | ||
| function makeUnique(arr) { | ||
| // Replace this comment and the next line with your code | ||
| console.log(arr); | ||
| const newArray = arr.filter(function(index, current) { | ||
| return arr.indexOf(index) === current; | ||
| }); | ||
| return newArray; | ||
jshortz marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| } | ||
| const uniqueValues = makeUnique(values); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,17 @@ | ||
| 'use strict'; | ||
| function createBase(base) { | ||
| // Replace this comment and the next line with your code | ||
| console.log(base); | ||
| return function(number) { | ||
| return number + base; | ||
| }; | ||
| } | ||
| const addSix = createBase(6); | ||
| const addSeven = createBase(7); | ||
| console.log(addSix(10)); // returns 16 | ||
| console.log(addSix(21)); // returns 27 | ||
| console.log(addSeven(21)); // returns 28 | ||
| // Do not change or remove anything below this line | ||
| module.exports = createBase; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.