Skip to content

Instantly share code, notes, and snippets.

View asvny's full-sized avatar
🎯
Focusing

Annamalai Saravanan asvny

🎯
Focusing
View GitHub Profile
function flatten(a) {
return Array.isArray(a) ? [].concat.apply([], a.map(flatten)) : [a];
}
@asvny
asvny / gist:fc898db988a4b74455c3
Last active August 29, 2015 14:26 — forked from SevInf/gist:09a1e7d913fa46d13265
Promises + generators
async(function*() {
console.log('start');
yield asyncFunction();
var value = yield asyncFunction();
console.log('value', value);
});
function asyncFunction() {
return new Promise((resolve, reject) => {
setTimeout(() => {
@asvny
asvny / assign.js
Created August 5, 2015 07:03
Object assign
if (!Object.prototype.assign) {
Object.prototype.assign = function() {
var args = [].slice.call(arguments),
target = args.shift();
return args.reduce(function(base, obj) {
Object.keys(obj).forEach(function(prop) {
if (obj.hasOwnProperty(prop)) {
base[prop] = obj[prop];
}
@asvny
asvny / gist:5524203bb5b826dedf97
Created June 10, 2015 12:31
Better Debounce function in Javascript
var debounce = function(func, wait) {
// we need to save these in the closure
var timeout, args, context, timestamp;
return function() {
// save details of latest call
context = this;
args = [].slice.call(arguments, 0);
timestamp = new Date();