This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function withBoxUnlocked(body) { | |
var closed = box.locked; | |
if (!closed) return body(); | |
box.unlock(); | |
try{ | |
return body(); | |
} finally{ | |
box.lock(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function MultiplicatorUnitFailure() {} | |
function primitiveMultiply(a, b) { | |
if (Math.random() < 0.5) | |
return a * b; | |
else | |
throw new MultiplicatorUnitFailure(); | |
} | |
function reliableMultiply(a, b) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function logFive(sequence) { | |
for (var i = 0; i < 5; i++) { | |
if (!sequence.next()) | |
break; | |
console.log(sequence.current()); | |
} | |
} | |
function ArraySeq(array) { | |
this.pos = -1; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; |
NewerOlder