Skip to content

Instantly share code, notes, and snippets.

import fs from 'fs'
var output = fs.readFileSystem('example.txt', 'utf8')
.trim()
.split('\n')
.map(line => line.split('\t'))
.reduce((customers, line) => {
customers[line[0]] = customers[line[0]] || []
customers[line[0]].push({
name: line[1],
@natasv
natasv / Once
Created January 21, 2016 19:08
function once(fn, context) {
var result;
return function() {
if(fn) {
result = fn.apply(context || this, arguments);
fn = null;
}
return result;
function debounce(func, wait, immediate) {
var timeout;
return function() {
var context = this, args = arguments;
var later = function() {
timeout = null;
if (!immediate) func.apply(context, args);
};
var callNow = immediate && !timeout;
clearTimeout(timeout);
var items = ['one', 'two', 'three', 'four'];
items.splice(items.length / 2, 0, 'hello');
var Subject = function() {
this.observers = [];
return {
subscribeObserver: function(observer) {
this.observers.push(observer);
},
unsubscribeObserver: function(observer) {
var index = this.observers.indexOf(observer);
if(index > -1) {