Skip to content

Instantly share code, notes, and snippets.

View juan-cortes's full-sized avatar
🐺
Woof

Juan Cortés Ross juan-cortes

🐺
Woof
  • Spain
  • 04:28 (UTC +02:00)
View GitHub Profile
@juan-cortes
juan-cortes / example.js
Last active June 28, 2018 00:14
Closure example function factory
function powerOfNFactory(power){
return function generatedFunction(subject){
return Math.pow(subject, power);
}
}
@juan-cortes
juan-cortes / example2.js
Last active June 28, 2018 01:54
Expanded example of closures in javascript, adding a counter
function powerOfNFactory(power){
var counter = 0
return function generatedFunction(subject){
counter++;
console.log(`Dyanmic Power of ${power} called ${counter} time/s`);
return Math.pow(subject, power);
}
}
var powerOf2 = powerOfNFactory(2);
@juan-cortes
juan-cortes / example3.js
Created June 28, 2018 00:39
Extended example of closures in javascript, adding memoization to the mix
function powerOfNFactory(power){
var counter = 0;
var cache = {};
return function generatedFunction(subject){
counter++;
console.log(`Dyanmic Power of ${power} called ${counter} time/s`);
if (cache[subject] === undefined) {
cache[subject] = Math.pow(subject, power);
} else {
console.log("Cached!");
@juan-cortes
juan-cortes / example0.js
Last active June 28, 2018 01:48
Example
function count() {
var counter = 0;
return function innerCount() {
return ++counter;
}
}
var counter1 = count(); //Create a new counter
var counter2 = count(); //Create a new counter
counter1(); //returns 1
@juan-cortes
juan-cortes / keybase.md
Created September 10, 2019 16:06
keybase.md

Keybase proof

I hereby claim:

  • I am juan-cortes on github.
  • I am user8528 (https://keybase.io/user8528) on keybase.
  • I have a public key ASBBXcGP6RSvLqXU26glD4PwfDWka7GmtYlM0FxvBI_2Igo

To claim this, I am signing this object: