Skip to content

Instantly share code, notes, and snippets.

@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){
// 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){
// 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() {
function logFive(sequence) {
for (var i = 0; i < 5; i++) {
if (!sequence.next())
break;
console.log(sequence.current());
}
}
function ArraySeq(array) {
this.pos = -1;
function MultiplicatorUnitFailure() {}
function primitiveMultiply(a, b) {
if (Math.random() < 0.5)
return a * b;
else
throw new MultiplicatorUnitFailure();
}
function reliableMultiply(a, b) {
function withBoxUnlocked(body) {
var closed = box.locked;
if (!closed) return body();
box.unlock();
try{
return body();
} finally{
box.lock();
}