Skip to content

Instantly share code, notes, and snippets.

function withBoxUnlocked(body) {
var closed = box.locked;
if (!closed) return body();
box.unlock();
try{
return body();
} finally{
box.lock();
}
function MultiplicatorUnitFailure() {}
function primitiveMultiply(a, b) {
if (Math.random() < 0.5)
return a * b;
else
throw new MultiplicatorUnitFailure();
}
function reliableMultiply(a, b) {
function logFive(sequence) {
for (var i = 0; i < 5; i++) {
if (!sequence.next())
break;
console.log(sequence.current());
}
}
function ArraySeq(array) {
this.pos = -1;
// Your code here.
function StretchCell(inner, width, height){
this.inner = inner;
this.width = width;
this.height = height;
};
StretchCell.prototype.minWidth = function(){
return Math.max(this.width, this.inner.minWidth());
}
StretchCell.prototype.minHeight = function() {
// Your code here.
function Vector(x,y){
this.x=x;
this.y=y;
};
Vector.prototype.plus = function(vector){
return new Vector(this.x+vector.x, this.y+vector.y)
}
Vector.prototype.minus = function(vector){
@TimBlock
TimBlock / 4.5
Created January 15, 2016 12:00
// Your code here.
function every(array,predicate){
for(var i = 0; i<array.length; i++){
if (!predicate(array[i]))
return false;
}
return true;
}
function some(array,predicate){
function average(array) {
function plus(a, b) { return a + b; }
return array.reduce(plus) / array.length;
}
var century = people(ancestry,function(person){
return Math.ceil(person.died / 100);
});
for(var cent in century){
function average(array) {
function plus(a, b) { return a + b; }
return array.reduce(plus) / array.length;
}
var byName = {};
ancestry.forEach(function(person) {
byName[person.name] = person;
});
var arrays = [[1, 2, 3], [4, 5], [6]];
console.log(arrays.reduce(function(a,b) {
return a.concat(b);
}));
// Your code here.
// → [1, 2, 3, 4, 5, 6]
// Your code here.
function deepEqual(obj1,obj2){
if(obj1===obj2) return true;
if (obj1 == null || typeof obj1 != "object" ||
obj2 == null || typeof obj2 != "object")
return false;
var propObj1 = 0, propObj2 = 0;