function Lib(ws) { return { clearElement: clearElement, insert: insert, send: send }; function clearElement(elem) { while(elem.firstChild) { elem.removeChild(elem.firstChild); } } function insert(obj, t, min, max) { min = min || 0; max = max || t.length; if(max - min < 1) { return min; } var avg = Math.floor((max + min) / 2); return (obj < t[avg]) ? insert(obj, t, min, avg) : insert(obj, t, avg+1, max); } function send(o) { ws.send(JSON.stringify(o)); } }