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
// italics for objects | |
(function (values) { | |
function toString(x) { | |
var v = x; | |
v = (v || v === "") ? JSON.stringify(v) : String(v); | |
if (typeof x === 'object') v = v.italics(); | |
return v; | |
} | |
function describe (i,j) { | |
var v1 = values[i], |
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 diff(a,b) { | |
var c = JSON.stringify, | |
i = function (x) {return x==null||typeof x!='object'}; | |
return (function d(a, b, p) { | |
var s, k, t=''; | |
if (i(a)||i(b)) | |
return a !==b ? p+'-'+c(b)+p+'+'+c(a) : ''; | |
for (k in a) | |
t += (k in b) | |
? ((s = d(a[k], b[k], p+' ')) ? p+k+':'+s : '') |
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
/* | |
0 | |
1 1 | |
1 1 1 | |
1 1 1 1 | |
1 1 1 1 1 | |
| | |
v |
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 (n, m) { | |
if (typeof m === 'undefined') { m = 1; } | |
if (typeof n === 'undefined') { throw new TypeError("Provide at least first number"); } | |
function randSort () { | |
return Math.random() * 2 - 1; | |
} | |
function getArr(n) { | |
var a = []; | |
for (var i = 1; i <= n; i++) { a.push(i); } |
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 decompress (s) { | |
var i, c, out = "", len, offset; | |
for (i = 0; i < s.length; i++) { | |
c = s.charCodeAt(i); | |
if (c >= 256 && c <= 288) { | |
len = c - 256; | |
offset = s.charCodeAt(++i); | |
out += out.substr(-offset, len); | |
} else { | |
out += s.charAt(i); |
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
class Shape { | |
constructor (type, ...args) { | |
super(); | |
switch (type) { | |
case 'rect': | |
return new Rectangle(...args); | |
case 'circle': | |
return new Circle(...args); | |
} | |
} |
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
/** | |
* @param {Node} node | |
* @template T | |
*/ | |
function Node (key, left, right) { | |
/** @property {T} key */ | |
this.key = key; | |
if (left) left.parent = this; | |
if (right) right.parent = this; | |
/** @property {Node<T>} left */ |
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 getType (value) { | |
let type = typeof value; | |
if (type === 'object') { | |
return value ? Object.prototype.toString.call(value).slice(8, -1) : 'null'; | |
} | |
return type; | |
} | |
[NaN, 0, 1, Infinity, // numbers | |
null, undefined, false, 'str', // other primitives |
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 assingImmutable(obj, toAdd) { | |
if (!_.isObjectLike(toAdd)) { | |
return toAdd; | |
} | |
key = _.first(path); | |
if (_.isArray(obj)) { | |
copy = _.slice(obj); | |
toAdd.forEach(function (value, idx) { | |
copy[idx] = assingImmutable(obj[idx], value); | |
}); |
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 pascalize(string) { | |
return string.replace(/-([a-z])/g, (_, c) => c.toUpperCase()); | |
} | |
function normalize(value) { | |
if (/^(null|true|false)$/.test(value)) { | |
return JSON.parse(value); | |
} | |
return value; | |
} |
OlderNewer