Skip to content

Instantly share code, notes, and snippets.

View davidjsalazarmoreno's full-sized avatar
🔥
Creating

David Salazar davidjsalazarmoreno

🔥
Creating
View GitHub Profile
function randInt(min,max){
var range = max - min;
// it actually does work the other way...
// if (range < 0) { throw new RangeError("min must be less than max"); }
var rand = Math.floor(Math.random() * (range + 1));
return min + rand;
}
@davidjsalazarmoreno
davidjsalazarmoreno / event-loop-ejemplo-1.js
Last active May 29, 2019 03:06
Entendiendo el Event Loop o Bucle de Eventos en Javascript
(() => {
console.log('1. Hola');
setTimeout(() => {
console.log('2. Mundo');
});
setTimeout(() => {
console.log('3. A todos');
}, 0);
@davidjsalazarmoreno
davidjsalazarmoreno / event-loop-ejemplo-2.js
Last active May 29, 2019 03:06
Entendiendo el Event Loop o Bucle de Eventos en Javascript
function segundoAlStack() {
var foo = 20 * 100;
return foo;
}
function primeroAlStack() {
var bar = 5;
var foo = segundoAlStack();
return bar + foo;
@davidjsalazarmoreno
davidjsalazarmoreno / event-loop-ejemplo-3.js
Last active May 29, 2019 03:06
Entendiendo el Event Loop o Bucle de Eventos en Javascript
while( queue.esperaPorMensaje() ) {
queue.procesaSiguienteMensaje();
}
@davidjsalazarmoreno
davidjsalazarmoreno / event-loop-ejemplo-4.js
Last active May 29, 2019 03:06
Entendiendo el Event Loop o Bucle de Eventos en Javascript
// El IIFE (Immediately-Invoked Function Expression) al ejecutarse añade el primer frame al stack de llamada
(() => {
// Añade un frame al stack de llamada
console.log('1. Hola');
// WebApi: Agrega un mensaje a la cola
setTimeout(() => {
console.log('2. Mundo');
});
const foo = 100
const bar = 20
// La línea es  -  o ++ (en cuyo caso disminuirá / incrementará el siguiente token).
bar
++
foo
/*
La intención es que se interptete así
bar++;
const bar = 'bar'
let foo = 'baz'
const bazzz = 'baaarrr',
fooos = 'baaam'
function hello(world) {
let greeting = 'Hello '
if (world)
// retorna undefined
function bad() {
return
'bad';
}
function good() {
return 'good'
}
var n = 9;
var ar = [10, 20, 20, 10, 10, 30, 50, 10, 20]
function sockMerchant(n, arr) {
const hash = new Map();
let count = 0;
for(let i = 0; i < n; i++) {
const sock = arr[i];
if (hash.get(sock) == 1) {
function jumpingOnClouds(arr) {
const length = arr.length;
let jumps = 0;
for(let i = 0; i <= length; i++) {
const canIJumpTwoClouds = arr[i + 2] === 0;
if (canIJumpTwoClouds) {
jumps += 1;
i += 1;
continue;