Skip to content

Commit c6cfd24

Browse files
committed
added notes on filter (more for my use cases article)
1 parent 3682550 commit c6cfd24

6 files changed

+210
-4
lines changed

Arrraynoodling.js

+25-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
const cheese = [1,2,3,4,5,6,7,8]
44
const wheel = [9,10,11,12,13,14]
5+
console.log(Array.of(cheese,wheel));
56

6-
console.log(Array.of(cheese,wheel)); // [1]
7-
Array.of(1, 2, 3); // [1, 2, 3]
7+
console.log(Array.of(1, 2, 3));
88
Array.of(undefined);
99

1010
const forest = 'There are deers , bears and foxes here'
@@ -14,3 +14,26 @@ console.log(forestArray)
1414
console.log(animals)
1515

1616

17+
// findSum(5) should return 8 (3 + 5)
18+
19+
// findSum(10) should return 33 (3 + 5 + 6 + 9 + 10)
20+
21+
22+
23+
function findSum(n) {
24+
const divide3 = 3 % n
25+
const divide5 = 5 % n
26+
console.log(divide3)
27+
console.log(divide5)
28+
}
29+
30+
console.log(findSum(10))
31+
32+
//You will be provided with an initial array (the first argument in the destroyer function), followed by one or more arguments. Remove all elements from the initial array that are of the same value as these arguments.
33+
34+
function destroyer(arr) {
35+
// Remove all the values
36+
return arr;
37+
}
38+
39+
destroyer([1, 2, 3, 1, 2, 3], 2, 3);

arraymethods.md

+10-2
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,20 @@ Filter is a method on an array that takes a callback and you can (in that callba
114114

115115
IF YOU ARE SEARCHING THROUGH EXISTING DATA YOU SHOULD FILTER IT.
116116

117+
You can filter by booleans , Datatypes (all sorts of stuff).
118+
117119
#### filter() syntax
118120

119121
```Javascript
120122

121123
const totalPurchases = transactions.filter(transaction => transaction.type === 'purchase').length
122124

125+
126+
const bouncer = (arr) => {
127+
return arr.filter(Boolean)
128+
}
129+
130+
// Filters for true values (FCC Challange ^^)
123131
```
124132

125133
### .map()
@@ -312,8 +320,8 @@ var arr2 = [3, 4, 5];
312320
arr1 = arr1.concat(arr2);
313321
// With spread syntax this becomes:
314322

315-
var arr1 = [0, 1, 2];
316-
var arr2 = [3, 4, 5];
323+
let arr1 = [0, 1, 2];
324+
let arr2 = [3, 4, 5];
317325
arr1 = [...arr1, ...arr2];
318326
```
319327

bigO.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Big O notes
2+
3+
With big O we express runtime in terms of how quickly it grows relative to the input as the input gets arbitrarily large.
4+
5+
Broken down it looks like this:
6+
7+
1. How quickly the runtime grows.
8+
9+
2. Relative to the input.
10+
11+
3. As the input gets arbitrarily large.

es6notes.md

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Jason's Es6 Notes
2+
3+
1. Let & Const vs var
4+
5+
2. Arrow functions and defaulr arguements
6+
7+
3. Template strings & string improvements
8+
9+
4. Destructuring
10+
11+
5. Interables & Loops
12+
13+
6. Array Improvements
14+
15+
7. Spread & Rest
16+
17+
8. Promises
18+
19+
9. JS modules & NPM
20+
21+
10. Object Orientated JS
22+
23+
## Let & Const vs Var
24+
25+
26+
### Scope
27+
28+
```Javascript
29+
30+
var dogYears = age * 7;
31+
32+
```
33+
34+
#### Scope w/Var
35+
36+
Looking at the above var what do you see ?
37+
you see a variable you can call anywhwere which can cause problems when you want to just call something once or are using a temporary variable.
38+
39+
It is best to put vars inside a function (since you are controlling it's scope)but they must be WITHIN the function for it to play well.
40+
41+
### Scope w/ Let & Const
42+
43+
```Javascript
44+
45+
const dogYears1 = age * 7;
46+
47+
```
48+
49+
The const declaration creates a read-only variable - this does not mean the value is immutable (it isn't unless we use object.freeze) what it DOES mean is that the variable cannot be reassigned so its parameters can be altered but what it is itself cannot be changed (i.e we cannot change the variables name to catLives but we can change it to be 9)
50+
51+
LET AND CONST ARE BLOCK SCOPED
52+

jsvalueorreference.md

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
## JS: Value or reference ?
2+
3+
Short answer: Passing primitive types (strings numbers booleans) are passed by object. Objects are passed by reference.
4+
5+
````Javascript
6+
7+
var a;
8+
function foo(a) {
9+
10+
}
11+
12+
```
13+
14+
The followup question would be:

usestrict.md

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# Use Strict in JavaScript
2+
3+
What is use Strict ?
4+
5+
Use Strict allows you to place a function or program in what is called a "Strict Operating Context" Code that would usually fail silently or been ignored would not generate errors / throw exceptions. This directs you to errors in your code quicker.
6+
7+
You can enable this by typing it in (as a string) "use strict". These are not special keywords , it is a string. The reason why is because when it was implimented not all browsers supported it and if older browsers read it it would have failed.
8+
9+
JS reads use strict 2 ways - as a string (as mentioned) or as a function (below)
10+
11+
c
12+
13+
If you run it as a function essentially you would just put the functions in strict mode within the scope of the strictCode() function (or whatever you name it)
14+
15+
## Strict rules & Changes
16+
17+
NTS: It seems like strict mode is similiar to using a linter.Except while a linter will call you out Strict will throw an error.
18+
19+
20+
### Defining Variables
21+
22+
1. Using a variable before it is defined throws an error. (Like with ESlint Airbnb config) in js there is always a global object where the global variables and functions go
23+
24+
- In the browser this is the window.
25+
26+
- In Node this is an object called 'global'.
27+
28+
### syntax
29+
30+
```Javascript
31+
32+
// in browser
33+
asim =1;
34+
console.log(window.asim)
35+
// in node
36+
console.log(global.asim)
37+
```
38+
39+
A problem with this is it can cause problems when calling variables, especially in larger files (i.e the kind you might use in production).
40+
41+
###example:
42+
43+
```Javascript
44+
45+
const value = 0
46+
47+
//pretend we have gone down 400 lines and attempt to call the value variable and reassign it like so:
48+
49+
values = 1;
50+
51+
if (value > 0 ) {
52+
console.log('Hello')
53+
}
54+
55+
// so as we might see here i might expect it to print hello and realized I meant to set VALUE not VALUES. if we were to use STRICT mode it would return an undefined error - in my personal case my ESlinter would cover this. But it is good to know when working in a professional setting.'use strict ' stops these syntax errors by calling them out for you
56+
```
57+
58+
## Reserved Words
59+
60+
2. As we know , let and const are words reserved for ES6 - lots of words are reserved for special use in JS , without strict mode this would not throw an error.
61+
62+
```Javascript
63+
64+
Const let = 1;
65+
66+
// Uncaught SyntaxError: Unexpected strict mode reserved word.
67+
```
68+
69+
## Cannot delete functions,variables or function arguements
70+
71+
I.e - without strict mode you can delete functions variables or function arguements you would do it by doing this:
72+
73+
``` Javascript
74+
75+
const foo = 0;
76+
delete foo
77+
78+
function moo(arguement) {
79+
delete arg;
80+
};
81+
// these would work normally but in strict mode throws errors.
82+
```
83+
84+
## Calling eval('')
85+
86+
eval() lets you run any code as an arguement as long as you pass it as a string. This can cause security issues.
87+
88+
```Javascript
89+
var eval = 1;
90+
// causes error in strict mode
91+
92+
93+
eval("var a = 1");
94+
console.log(a);
95+
// above code can cause an issue with the namespace and the console log would not normally work as it is messing with its own block
96+
```
97+
98+
Anyway with use strict any variables you print within eval stays within it so when you console.log it in the same manner as the example above - you throw an error (a is not defined).

0 commit comments

Comments
 (0)