Skip to content
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

Develop #12

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
228 changes: 225 additions & 3 deletions 1-hoisting/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,26 @@ function sayHello(name) {
let message = sayHello(username);
var nextMessage = sayHello('Test');
```
//- re-write
```js
// Declaration Phase
username = undefined;
brother;

function sayHello(name){
return `Hello ${name}`
}
message;
nextMessage = undefined;

// Execution Phase
username = 'Arya';
brothers = ['John', 'Ryan', 'Bran'];
console.log(username, brothers[0]); // 'Arya', 'John';

message = sayHello(username);
nextMessage = sayHello('Test');
```

2.

Expand All @@ -35,6 +55,22 @@ let message = sayHello(username);
var nextMessage = sayHello('Test');
```

```js
// Declaration Phase

username = undefined;
number;
function sayHello(name){
return `Hello ${name}`;
}
message;
nextMessage = undefined;

Execution Phase
console.log(username, number); // ReferenceError: Can not access 'number before initialization

```

3.

```js
Expand All @@ -51,6 +87,19 @@ let message = sayHello(username);
var nextMessage = sayHello('Test');
```

```js
// Declaration Phase
username;
number;
sayHello;
message;
nextMessage = undefined;

//Execution Phase

console.log(username, number) // ReferenceError: Cannot access 'username' before initialization
```

4.

```js
Expand All @@ -67,6 +116,19 @@ let sayHello = function (name) {
var nextMessage = sayHello('Test');
```

```js
// Declaration Phase
username = 'Arya';
number = 21;
message;
sayHello;
nextMessage = undefined;

//Execution Phase
username = 'Arya';
console.log(username,number) // ReferenceError: Cannot access 'number' before initialization
```

5.

```js
Expand All @@ -75,7 +137,13 @@ console.log(age);
var name = 'Lydia';
let age = 21;
```

```js
name = undefined;
age;
// Execution Phase
console.log(name) // undefined
console.log(age) // ReferenceError: Cannot access 'age' before initialization
```
6.

```js
Expand All @@ -87,6 +155,28 @@ function sayHi(name) {
}

sayHi();
```
```js
// Declaration Phase
function sayHi(name){
console.log(name);
console.log(age);
var name = 'Lydia';
let age = 21
}

//Execution Phase

//F.E.C

//D
name = undefined;
age;

//Execution Phase
console.log(name) // undefined
console.log(age) // ReferenceError: Cannot access 'age' before initialization

```

6.
Expand All @@ -101,6 +191,24 @@ function sayHi(name) {
}
```

```js
// Declaration Phase
function sayHi(name) {
console.log(name);
console.log(age);
var name = 'Lydia';
let age = 21;
}
//Execution Phase
//F.E.C
//Declaration Phase
name = undefined;
age;

//Execution Phase
console.log(name) // undefined;
console.log(age) // ReferenceError: Cannot access 'age' before initialization
```
7.

```js
Expand All @@ -112,14 +220,43 @@ let sayHi = function sayHi(name) {
let age = 21;
};
```

```js
// Declaration Phase
function sayHi(name) {
console.log(name);
console.log(age);
var name = 'Lydia';
let age = 21;
}
//Execution Phase
//F.E.C
//Declaration Phase
name = undefined;
age;

//Execution Phase
console.log(name) // undefined;
console.log(age) // ReferenceError: Cannot access 'age' before initialization
```
8.

```js
let num1 = 21;
console.log(sum);
var sum = num1 + num2;
let num2 = 30;
```
```js
//Declaration Phase

num1;
sum = undefined;
num2;

//Execution Phase
num1 = 21;
// ReferenceError: num2 is not defined

```

9.
Expand All @@ -132,14 +269,54 @@ let sum2 = addAgain(num1, num2, 4, 5, 6);
let add = (a, b, c, d, e) => {
return a + b + c + d + e;
};
function addAgian(a, b) {
function addAgain(a, b) {
return a + b;
}
let num2 = 200;

let sum = add(num1, num2, 4, 5, 6);
```

```js

num1 = undefined;
sum2;
add;
function addAgain(){
return a + b;
}
num2;
sum;
//Execution Phase
num1 = 21;
sum2 = // function call
// F.E.C sum2
//F.E.C D
a = undefined;
b = undefined;
//
//F.E.C E
a = 21;
b = num2;
// num2 is not defined

add = // function call
//F.E.C
//Declaration Phase
a = undefined;
b = undefined;
c = undefined;
d = undefined;
e = undefined;
// Execution Phase
a = 21;
b=200;
c=4;
d=5;
e=6;
return a+b+c+d+e // 236
sum = 236;
```
10.

```js
Expand All @@ -155,6 +332,27 @@ let add = (a, b) => {
};
```

```js
// Declaration Phase
function test(a) {
let num1 = 21;
return add(a, num1);
}
sum;
add;
// Execution Phase
sum = //function call
// F.E.C
// F.E.C D
a = undefined;
b = undefined;
// F.E.C E
a = 100;
b = 21;
return // 121


```
11.

```js
Expand All @@ -169,3 +367,27 @@ function add(a, b) {
return a + b;
}
```
```js
// Declaration Phase
function test(a) {
let num1 = 21;
return add(a, num1);
}
sum;
function add(a, b) {
return a + b;
}
// Execution Phase
sum = //function call
//F.E.C
//F.E.C D
a = undefined;
num1;

// F.E.C E
a = 100;
num1 = 21;
return 121

sum = 121
```
22 changes: 20 additions & 2 deletions 2-higher-order-functions/eloquent/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,38 @@
let arrays = [[1, 2, 3], [4, 5], [6]];

// Your code here.
arrays.reduce((a, c) => a.concat(c), []);
// → [1, 2, 3, 4, 5, 6]

// Challenge 2. Your own loop
// Your code here.

loop(3, n => n > 0, n => n - 1, console.log);
// Your code here.

function loop(num, test, test2, op){
for(let i = 0; i <= num; i++){
if(test(i)){
op(i);
num = test2(num)

}
}
}

// → 3
// → 2
// → 1

// Challenge 3. Everything
function every(array, test) {
// Your code here.
}
let result = true
for(let item of array){
result = result && test(item)
}
return result;
}


console.log(every([1, 3, 5], n => n < 10));
// → true
Expand Down
Loading