Skip to content

Instantly share code, notes, and snippets.

View rxluz's full-sized avatar

Ricardo Luz rxluz

View GitHub Profile
@rxluz
rxluz / peopleData2.js
Last active January 20, 2019 06:50
Big O in JS: The basic that you need to know, see more at: https://medium.com/p/a5abb45570fa
const people = [
{
name: "Joseph",
age: 32,
gender: "male",
},
{
name: "Anna",
age: 27,
gender: "female",
var names = ["Ana", "Mary", "John", "Steban"];
for (var x = 0; x < names.length; x++) {
console.log(names[x]);
}
var names = ["Ana", "Mary", "John", "Steban"];
for (var currentIndex in names) {
console.log(names[currentIndex]);
}
var names = ["Ana", "Mary", "John", "Steban"];
names.forEach(name => console.log(name));
const people = [
{
name: "Joseph",
age: 32,
gender: "male",
},
{
name: "Anna",
age: 27,
gender: "female",
const people = [
{
name: "Joseph",
age: 32,
gender: "male",
},
{
name: "Anna",
age: 27,
gender: "female",
async function run() {
var test = {
value: 0,
};
const testss = await new Promise(accept =>
setTimeout(() => ((test.value = 90), console.log(test.value), accept()), 0),
);
@rxluz
rxluz / jsENUM.js
Last active January 11, 2019 12:17
//enum is a reserved word in new ES6 reserved words list, that's the reason the method call ENUM_
class Enum_ {
constructor(...list) {
const objList = list.reduce((acummulator, value) => {
acummulator[value] = Symbol(value);
return acummulator;
}, {});
return Object.freeze(objList);
}
/* WITHOUT STATE PATTERN EXAMPLE */
class TVRemoteWithoutStatePattern {
constructor() {
this.channel = 1;
}
setChannel(channel) {
this.channel = channel;
}
@rxluz
rxluz / DESIGN_PATTERNS_statePattern.js
Last active January 18, 2019 02:44
JS Design Patterns: State, see more at: https://medium.com/p/4a8e1f30b62d
/* STATE PATTERN EXAMPLE */
class TVRemoteChannel1State {
displayStatus() {
console.log("Hello now watch sports on channel 1");
}
}
class TVRemoteChannel2State {
displayStatus() {