function Dog (name, breed) {
this.name = name;
this.breed = breed;
}
Dog.prototype.bark = function () {
console.log('Arf, my name is ', this.name);
};
const cody = new Dog('Cody', 'pug');
cody.bark();
const arr = [1, 2, 3];
const newArray = arr
.map(item => item * 3)
.filter(item => item % 2 === 0);
console.log(newArray) // [6]
const composedFunction = compose(f, g)
composedFunction(x) === f(g(x))
function factorial (x) {
let result = x;
for (let i = x - 1; i > 1; i--) {
result *= i;
}
return result
}
function factorial(x) {
return x === 1 ? x : x * factorial(x - 1);
}
Numbers, strings, booleans
Objects, arrays
let obj = {a: 'someData'};
lolFunction(obj);
console.log(obj) // what are we going to get?
let obj = {a: 'someData'};
let newObj = lolFunction(obj);
// now I know that if I want to use obj, I'm using obj
// and if I want to use newObj, I'm getting newObj
Prepend
Prepend
Prepend
Append
Append
Append
Insert
Insert
Insert
This is structural sharing!
Copy (Mutation)
0x70
0x71
0x72
const arr1 = ["green", "pink", "blue"];
arr1
Copy (Mutation)
0x70
0x71
0x72
0x73
0x74
0x75
arr1
arr2
Copy (Mutation)
0x70
0x71
0x72
0x73
0x74
0x75
var arr1 = ["green", "pink", "blue"];
var arr2 = ["green", "pink", "blue"];
arr1 === arr2 // false
// remember that === between two objects compares
// address in memory
Copy (Immutable)
0x70
0x71
0x72
const arr1 = [1, 2, 3];
Copy (Immutable)
0x70
0x71
0x72
..........um, we're done?
const arr1 = [1, 2, 3];
const arr2 = [1, 2, 3];
arr1 === arr2 // true
// we could just re-use the memory
// we've already allocated
Commit B
(message: "I just commited some changes!")
Tree (/my-prj)
Tree (my-prj/js)
Tree (my-prj/css)
Blob (my-prj/js/app.js)
Blob (my-prj/js/utils.js)
Blob (my-prj/css/style.css)
Commit C
Commit A
/my-prj
/js
app.js
utils.js
/css
style.css
Commit B
(message: "I just commited some changes!")
Tree (/my-prj)
Tree (my-prj/js)
Tree (my-prj/css)
Blob (my-prj/js/app.js)
Blob (my-prj/js/utils.js)
Blob
(my-prj/css/style.css)
Commit C
(message: "I just changed style.css!")
/my-prj
/js
app.js
utils.js
/css
style.css (CHANGED!)
Tree` (/my-prj)
Tree` (my-prj/css)
Blob`
(prj/css/style.css)
git clone https://github.com/FullstackAcademy/fvs