This file contains 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 getHash (v) { | |
return v.x+'-'+v.y+'-'+v.z; | |
} | |
function solve(input) { | |
var l = input.length, | |
map = {}; | |
while(l--) { |
This file contains 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 getHash (v) { | |
return v.x+'_'+v.y+'_'+v.z; | |
} | |
function solve(input) { | |
var l = input.length, | |
map = {}, |
This file contains 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
// multiline conditional operator (source: three.js) | |
var newTime = self.performance !== undefined && self.performance.now !== undefined | |
? self.performance.now() | |
: Date.now(); |
This file contains 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
<!-- To avoid spaces between inline-block elements and still have enter between them in the code. --> | |
<ul> | |
<li><!-- | |
--></li> | |
<li><!-- | |
--></li> | |
</ul> |
input: var a = [2, 3, 5]
Task: we want to fill array with undefined
s to 6th element.
output: [2, 3, 5, undefined, undefined, undefined]
ES5 solutions:
a.length = 6
result:[2, 3, 5, undefined x 3]
Problem: this array has sparse elements (holes) on elements 3-5. We can iterate through it like:for (i = a.length ; i-- ;) {}
, but when we iterate like:a.forEach(callback)
it only goes through iterable values.
let / const declarations do hoist, but they throw errors when accessed before being initialized (instead of returning undefined as var would)
let x = 'outer scope';
console.log(x); // => outer scope
(function() {
console.log(x); // => ReferenceError (let is hoisted, but doesn't allow accessing)
console.log(y); // => undefined (var is hoisted and allows accessing)
This file contains 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
// FUNCTIONS | |
// use on babeljs.io/repl | |
function declaration() { | |
console.log('declaration'); | |
} | |
var expression = function() { |
This file contains 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
// # Arrays | |
// var a = ['a', 'b', 'c']; | |
// var i = a[0]; | |
// var j = a[1]; | |
// var k = a[2]; | |
// var [i, j, k] = a; | |
// var [i, j, k] = ['a', 'b', 'c']; |
This file contains 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 text = `something`; | |
// var template = '' + | |
// '<div>' + | |
// '<input>' + | |
// '</div>'; | |
// console.log(template); | |
// var template2 = ` |
OlderNewer