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
domElems.forEach((elem, i) => { | |
elem.addEventListener('click', () = { | |
console.log(i); | |
}); | |
}); |
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
// domElems is an array of DOM elements of length 5 | |
for (var i = 0; i < domElems.length; ++i) { | |
((j) => { | |
domElems[j].addEventListener('click', () => { | |
console.log(j); | |
}); | |
})(i); | |
} |
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
// domElems is an array of DOM elements of length 5 | |
for (var i = 0; i < domElems.length; ++i) { | |
domElems[i].addEventListener('click', () => { | |
console.log(i); | |
}); | |
} |
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
var theThing = null; | |
var replaceThing = function () { | |
var originalThing = theThing; | |
var unused = function () { | |
if (originalThing) | |
console.log("hi"); | |
}; | |
theThing = { | |
longStr: new Array(1000000).join('*'), | |
someMethod: function () {} |
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
import makeHttpRequest from 'http-util'; | |
const baseUrl = 'http://foo.com'; | |
export function getUser(id) { | |
const response_body = makeHttpRequest(`${baseUrl}/user/${id}`); | |
// blah... | |
} |
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
function addX(x) { | |
return y => x + y; | |
} | |
let add42 = addX(42); | |
let i = add42(8); | |
assert(i === 50); |
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 is a functor | |
struct add_x { | |
add_x(int x) : x(x) {} | |
int operator()(int y) { return x + y; } | |
private: | |
int x; | |
}; | |
// Now you can use it like this: |
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
function filterNamesContaining(someStr, names) { | |
let rtn = []; | |
for (let name of names) { | |
if (name.indexOf(someStr) !== -1) { rtn.push(name); } | |
} | |
return rtn; | |
} |
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
function filterNamesContaining(someStr, names) { | |
// filter out names that contain `someStr` as a substring | |
return names.filter(name => name.indexOf(someStr) !== -1); | |
} |