Skip to content

Instantly share code, notes, and snippets.

View nchDev-js's full-sized avatar
:octocat:
Open for new opportunities

Nataly nchDev-js

:octocat:
Open for new opportunities
  • Benidorm, Spain
  • 15:32 (UTC +01:00)
View GitHub Profile
const EXTENSION_TYPE = {
0x01: 'PlainText',
0xF9: 'GraphicControl',
0xFE: 'Comment',
0xFF: 'Application'
};
/**
* Returns total length of data blocks sequence
*
@nchDev-js
nchDev-js / chain-of-responsibility.js
Created February 20, 2021 19:05
Design Patterns / BEHAVIORAL
class Account {
pay(orderPrice) {
if (this.canPay(orderPrice)) {
console.log(`Paid ${orderPrice} using ${this.name}`);
} else if (this.incomer) {
console.log(`Cannot pay using ${this.name}`);
this.incomer.pay(orderPrice);
} else {
console.log("Unfortunately, not enough money");
}
@nchDev-js
nchDev-js / adapter.js
Created February 20, 2021 19:00
Design Patterns / STRUCTURAL
class Engine2 {
simpleInterface() {
console.log("Engine 2.0 - tr-tr-tr");
}
}
class EngineV8 {
complecatedInterface() {
console.log("Engine V8! - wroom wroom!");
}
@nchDev-js
nchDev-js / abstract-factory.js
Created February 20, 2021 18:57
Design Patterns / CREATIONAL
function bmwProducer(kind) {
return kind === "sport" ? sportCarFactory : familyCarFactory;
}
function sportCarFactory() {
return new Z4();
}
function familyCarFactory() {
return new I3();
@nchDev-js
nchDev-js / 01_objects.js
Last active February 20, 2021 19:07
AIRBNB_good_vs_bad
// use computed property names when creating objects with dynamic property names.
function getKey(k) {
return `a key named ${k}`;
}
// bad
const obj = {
id: 5,
name: 'San Francisco',
};
@nchDev-js
nchDev-js / random.js
Last active February 20, 2021 19:08
get random color from array
// will return a random color from the array
const colors = [
"blue",
"white",
"green",
"navy",
"pink",
"purple",
"orange",
"yellow",