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 Watch (obj, scheme, handler, pathOriginal = [], _obj = {}) { | |
scheme.forEach(fieldName => { | |
const path = pathOriginal.map(e => e); | |
if (typeof fieldName === 'string') { | |
path.push(fieldName); | |
if (['string', 'number', 'boolean'].indexOf(typeof obj[fieldName]) !== -1 || obj[fieldName] === null) { | |
_obj[fieldName] = obj[fieldName]; | |
delete obj[fieldName]; | |
Object.defineProperty(obj, fieldName, { | |
enumerable: true |
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
let array = [1, 'b', 3, 'f', 'f', 'd', 'a', 9, 'b', 8, 'd', 4, 9, 'a', 5, 10, 3, 'c', 8, 7, 7, 6, 1, 'g', 'a', 'g', 4, 'e', 9, 8, 6, 5, 5, 2, 'c', 'd', 'e', 1, 6, 4, 2, 'b', 3, 10, 'e', 'f', 2, 'c', 10, 'g', 7]; | |
array = array.filter((e, i, l) => i == l.lastIndexOf(e)); | |
console.log(array); // => [ 'a', 9, 8, 5, 'd', 1, 6, 4, 'b', 3, 'e', 'f', 2, 'c', 10, 'g', 7 ] |
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
const object = {a: 1, b: 2}; | |
Object.defineProperty(Object.prototype, Symbol.iterator, { | |
enumirable: false | |
, configurable: true | |
, get: () => function * () { | |
for (const key of Object.keys(this)) | |
yield [key, this[key]]; | |
} | |
}); |
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
Object.defineProperty(Array.prototype, 'first', { | |
enumerable: false | |
, configurable: true | |
, get: function () { return this[0]; } | |
, set: function (value) { | |
return this.length ? this[0] = value : this.push(value) && value; | |
} | |
}); | |
Object.defineProperty(Array.prototype, 'last', { |
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
const n = 1000; | |
const buff = new Int16Array(n + 1); | |
for (let i = 3; i < buff.length; i += 2) { | |
buff[i - 1] = 1; | |
if (buff[i] == 0) | |
for (let j = i + i; j < buff.length; j += i) | |
buff[j] = 1; | |
} |
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
class User { | |
constructor (isAdmin = false) { | |
const user = this; | |
user.isAdmin = isAdmin; | |
User.all.push(user); | |
} | |
static get admins () { | |
return User.all.filter(user => user.isAdmin); | |
} |
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
Object.defineProperty(Map.prototype, 'toJSON', { | |
enumerable: false | |
, configurable: true | |
, get: () => function () { | |
const obj = {}; | |
for (const key of this.keys()) | |
obj[key] = this.get(key); | |
return obj; |
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
Array.isEqual = function (...arrays) { | |
if (arrays.length == 0) return false; | |
if (arrays.length == 1) return true; | |
const ctrl = arrays[0] | |
, length = ctrl.length; | |
for (let i = 1; i < arrays.length; i++) { | |
const array = arrays[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
function showPerson1 (name, family, age) { | |
console.log(name, family, age); | |
} | |
function showPerson2 ({name, family, age}) { | |
showPerson1(name, family, age); | |
} | |
const name = 'Aleksey', family = 'Danchin', age = 24; |
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
class Point { | |
constructor () { | |
const point = this; | |
point.x = 0; | |
point.y = 0; | |
point.color = 'red'; | |
} | |
moveTo (x, y) { |