server/www/lib.js

27 lines
575 B
JavaScript

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 == undefined ? 0 : min;
max = max == undefined ? t.length : max;
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));
}
}