Skip to content

Instantly share code, notes, and snippets.

View kepta's full-sized avatar
🐒
What

Kushan Joshi kepta

🐒
What
  • Toronto
View GitHub Profile
const isRequired = () => { throw new Error('param is required'); };
function filterEvil(array, evil = isRequired()) {
return array.filter(item => item !== evil);
}
function firstItem([first, second] = ['luke', 'skywalker']) {
return first;
}
function findName({ name } = { name : 'darth' }) {
return name;
}

In this article I will take a very simplistic approach in understanding memory leaks and I will also attempt to diagnose them.

In todays world of abundant memory, we seldom worry about memory leakages. But I hate to tell you that we live in a real world and nothing comes for free.

Oh my fancy functional programming

Disclosure: I absolutely love functional programming. Functional programming is cool and with the new ES6 syntax it becomes even cooler.

const arrayAddFirst = (a, b) => [a, ...b];
result = newData.reduce((p,r) => arrayAddFirst(r, p), []);
@kepta
kepta / memory-3.js
Last active February 5, 2018 05:12
for(var i = 0; i < newData.length; i++) {
for(var j = 0; j < i; j++) {
// stuff here
}
}
var x = 0;
while(x < 5) {
console.log(x); // Warning! do not try this at home
}
var x = [ [1] ];
for(var i = 1; i < 100000; i++) {
x.push(arrayAddFirst(i, x[i-1])); // Warning! do not try this at home
}
function sayHi() {
var allNames = [];
var emoji = '👋';
return name => {
allNames.push(name);
return emoji + name;
}
}
function sayHi() {
var allNames = [];
var emoji = '👋';
return name => {
allNames.push(name);
return emoji + name;
}
}