Skip to content

Instantly share code, notes, and snippets.

View KKrisu's full-sized avatar
💭
Saving the world, please don't disturb

Kris Kesy KKrisu

💭
Saving the world, please don't disturb
  • Gniezno, Poland
View GitHub Profile
function getHash (v) {
return v.x+'-'+v.y+'-'+v.z;
}
function solve(input) {
var l = input.length,
map = {};
while(l--) {
function getHash (v) {
return v.x+'_'+v.y+'_'+v.z;
}
function solve(input) {
var l = input.length,
map = {},
@KKrisu
KKrisu / rules.js
Created October 24, 2014 22:35 — forked from anonymous/rules.js
// multiline conditional operator (source: three.js)
var newTime = self.performance !== undefined && self.performance.now !== undefined
? self.performance.now()
: Date.now();
@KKrisu
KKrisu / arrays.js
Last active August 29, 2015 14:14
Playing with ES5
We couldn’t find that file to show.
@KKrisu
KKrisu / tricks.html
Created April 21, 2015 10:58
CSS HTML tricks
<!-- To avoid spaces between inline-block elements and still have enter between them in the code. -->
<ul>
<li><!--
--></li>
<li><!--
--></li>
</ul>
@KKrisu
KKrisu / fill_array_without_holes.md
Last active August 29, 2015 14:25
JS Sparse Arrays

input: var a = [2, 3, 5]
Task: we want to fill array with undefineds to 6th element.
output: [2, 3, 5, undefined, undefined, undefined]

ES5 solutions:

  1. 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.
@KKrisu
KKrisu / TDZ_Temporal_Dead_Zone.md
Last active August 29, 2015 14:25
ES6 var / let / const

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)
@KKrisu
KKrisu / functions.js
Last active January 19, 2016 21:05
JS functions
// FUNCTIONS
// use on babeljs.io/repl
function declaration() {
console.log('declaration');
}
var expression = function() {
@KKrisu
KKrisu / deconstructing.js
Created February 16, 2016 13:38
ES6 Deconstructing
// # 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'];
@KKrisu
KKrisu / templates.js
Created February 16, 2016 13:42
ES6 Strings, Templates
// var text = `something`;
// var template = '' +
// '<div>' +
// '<input>' +
// '</div>';
// console.log(template);
// var template2 = `