-
Notifications
You must be signed in to change notification settings - Fork 83
adding testing exercises #41
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
sfarnsworthkum
wants to merge
8
commits into
rithmschool:master
Choose a base branch
from
sfarnsworthkum: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 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
de76c9c
adding testing exercises
5689647
partially finished recursion
ff1b382
fixed collectStrings solution to actually collect strings
a686bba
patially completed lodash exercises
93c4e0b
some fixes, and canvas project - still need to add timer
f0fe64e
some updates to lodash and es2015 exercises
14ffca6
call apply bind exercises
0d841c9
prototype exercises
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
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,4 +1,4 @@ | ||
| ## ES2015 Exercise | ||
| # ES2015 Exercise | ||
|
|
||
| Convert the following es5 code blocks into es2015 code: | ||
|
|
||
|
|
@@ -11,23 +11,36 @@ var person = { | |
| }.bind(this),1000) | ||
| } | ||
| } | ||
| var person2 = { | ||
| fullName: "Harry Potter", | ||
| sayHi: function(){ | ||
|
Contributor
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 can be simplified more: |
||
| setTimeout(() => { | ||
| console.log(`Your name is ${this.fullName}`) | ||
| },1000) | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ```javascript | ||
| var name = "Josie" | ||
| console.log("When " + name + " comes home, so good") | ||
| console.log(`When ${name} comes home, so good`); | ||
| //Steely Dan? | ||
|
Contributor
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. you know it! |
||
| ``` | ||
|
|
||
| ```javascript | ||
| var DO_NOT_CHANGE = 42; | ||
| DO_NOT_CHANGE = 50; // stop me from doing this! | ||
| const doNotChange = 42; | ||
| ``` | ||
|
|
||
| ```javascript | ||
| var arr = [1,2] | ||
| var temp = arr[0] | ||
| arr[0] = arr[1] | ||
| arr[1] = temp | ||
| var [a, b] = [1, 2]; | ||
| [a, b] = [b, a]; | ||
| ``` | ||
|
|
||
| ```javascript | ||
|
|
@@ -36,18 +49,24 @@ function double(arr){ | |
| return val*2 | ||
| }); | ||
| } | ||
|
|
||
| function double1(arr){ | ||
| return arr.map(value => value * 2); | ||
| } | ||
| ``` | ||
|
|
||
| ```javascript | ||
| var obj = { | ||
| numbers: { | ||
| a: 1, | ||
| b: 2 | ||
| } | ||
| } | ||
| } | ||
|
|
||
| var a = obj.numbers.a; | ||
| var b = obj.numbers.b; | ||
|
|
||
| var {a, b, c} = obj.numbers; | ||
| ``` | ||
|
|
||
| ```javascript | ||
|
|
@@ -62,14 +81,91 @@ function add(a,b){ | |
| } | ||
| return a+b | ||
| } | ||
| function add(a = 10, b = 10) { | ||
| return a + b; | ||
| } | ||
| //or better | ||
| var add = (a = 10, b = 10) => a + b; | ||
| ``` | ||
|
|
||
| Research the following functions - what do they do? | ||
|
|
||
| `Array.from` - | ||
| `Array.from` - It allows you to create arrays from array like objects, things with a length property and indexed elements - has the optional parameter .map() to perform a function on each element in the new array. which syntax would be like: Array.from(obj, mapFn, thisArg) Fancy using arrow functions: Array.from([1, 2, 3], x => x + x) //[2, 4, 6] | ||
|
|
||
| `Object.assign` - _not a deep clone_ but basically copies the enumerable and own properties from a source object to a target object. Uses get on source and set on target - so it assigns properties vs just copying or defining new properties example of cloning an object - BUT not a deep clone | ||
|
|
||
| ```javascript | ||
| var obj = {a: 1}; | ||
| var copy = Object.assign({}, obj) | ||
| console.log(copy); //{a: 1} | ||
| ``` | ||
|
|
||
| using to merge objects: | ||
|
|
||
| ```javascript | ||
| var o1 = {a : 1}; | ||
| var o2 = {b : 2}; | ||
| var o3 = {c : 3}; | ||
| var obj = Object.assign(o1, o2, o3); | ||
| console.log(obj); //{a: 1, b: 2, c: 3} | ||
| ``` | ||
|
|
||
| watch out when you merge objects with the same properties though ==> the properties are overwritten by other objects that have the properties later in the parameters order | ||
|
|
||
| ```javascript | ||
| var o1 = {a : 1, b: 1, c: 1}; | ||
| var o2 = {b : 2, c: 2}; | ||
| var o3 = {c : 3}; | ||
| var obj =Object.assign({}, o1, o2, o3); | ||
| console.log(obj); //{a: 1, b: 2, c: 3} | ||
| ``` | ||
|
|
||
| Also: | ||
|
|
||
| ```javascript | ||
| var v1 = 'abc'; | ||
| var v2 = true; | ||
| var v3 = 10; | ||
| var v4 = Symbol('foo'); | ||
|
|
||
| var obj = Object.assign({}, v1, null, v2, undefined, v3, v4); | ||
| // Primitives will be wrapped, null and undefined will be ignored. | ||
| // Note, only string wrappers can have own enumerable properties. | ||
| console.log(obj); // { "0": "a", "1": "b", "2": "c" } | ||
| ``` | ||
|
|
||
| `Object.assign` - | ||
| `Array.includes` - determines if an array includes a certain element, returns a boolean. | ||
|
|
||
| `Array.includes` - | ||
| syntax: | ||
|
|
||
| `String.startsWith` - | ||
| ```javascript | ||
| arr.includes(searchElement); | ||
| arr.includes(searchElement, fromIndex); | ||
| ``` | ||
|
|
||
| Parameters: the element to search for and the optional fromIndex: the position in this array at which to begin searching for the searched element, a negative value searches from the index of array.length + fromIndex. defaults to zero | ||
|
|
||
| ```javascript | ||
| var a = [1, 2, 3]; | ||
| a.includes(2); //true | ||
| a.includes(4); //false | ||
| ``` | ||
|
|
||
| `String.startsWith` - determines whether a string begins with the characters of a specified string, returning boolean | ||
|
|
||
| syntax: | ||
|
|
||
| ```javascript | ||
| stringWhatever.startsWith("thing I', searching for", position); | ||
| ``` | ||
|
|
||
| parameters: searchString: characters to be searched for at the start of this string position: (optional) the position in this string at which to begin searching for searchString, defaults to zero _Also case sensitive_ | ||
|
|
||
| ```javascript | ||
| //startswith | ||
| var str = 'To be, or not to be, that is the question.'; | ||
|
|
||
| console.log(str.startsWith('To be')); // true | ||
| console.log(str.startsWith('not to be')); // false | ||
| console.log(str.startsWith('not to be', 10)); // true | ||
| ``` | ||
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.
Good start and your code looks clean so far. Try to add the seconds timer and stop the game after 30 seconds have passed.