Run for a while
Gather feedback
Google proprietary
Google proprietary
Google proprietary
function bar(a) {
return a + 3;
}
function foo(x) {
return bar(5) + x;
}
function bar(a) {
return a + 3;
}
function foo(x) {
return 5 + 3 + x;
}
function bar(a) {
return a + 3;
}
function foo(x) {
return 8 + x;
}
// one of many array "built-ins"
let a = [1, 2, 3];
let mult = x => x * 2;
a.map(mult);
// prints 2, 4, 6
// If you wrote it by hand...
let a = [1, 2, 3];
let mult = x => x * 2;
let b = [];
for (let i = 0; i < a.length; i++) {
b[i] = mult(a[i], i, a);
}
// b is [2, 4, 6]
// Consider this case...
let a = [1, 2, 3];
let mult = x => x * 2;
function foo() {
return a.map(mult);
}
// Consider this case...
let a = [1, 2, 3];
let mult = x => x * 2;
function foo() {
// we inlined Array.map!
let b = [];
for (let i = 0; i < a.length; i++) {
b[i] = mult(a[i]);
}
return b;
}
// Consider this case...
let a = [1, 2, 3];
let mult = x => x * 2;
function foo() {
// we inlined Array.map...also mult.
let b = [];
for (let i = 0; i < a.length; i++) {
b[i] = a[i] * 2;
}
return b;
}
// Arrays can have "holes"
let a = [1, , 3];
a[1];
// prints undefined
// holes "see through" to
// the prototype
Array.prototype[1] = 'oh hai';
a[1];
// oh hai :/
Google proprietary