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
// Regex Golf | |
verify(/ca[rt]/, | |
["my car", "bad cats"], | |
["camper", "high art"]); | |
verify(/pr?op/, | |
["pop culture", "mad props"], | |
["plop"]); |
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
// Retry | |
function MultiplicatorUnitFailure() {} | |
MultiplicatorUnitFailure.prototype = Object.create(Error.prototype); | |
function primitiveMultiply(a, b) { | |
if (Math.random() < 0.5) | |
return a * b; | |
else | |
throw new MultiplicatorUnitFailure(); | |
} |
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
// Artificial Stupidity | |
function SmartPlantEater() { | |
this.energy = 20; | |
this.last_reproduction = 0; | |
} | |
SmartPlantEater.prototype.act = function(view) { | |
var space = view.find(" "); | |
if (this.energy > 60 && space && this.last_reproduction > 60) { | |
this.last_reproduction = 0; | |
return {type: "reproduce", direction: space}; |
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
// A Vector Type | |
function Vector(x, y){ | |
this.x = x; | |
this.y = y; | |
}; | |
Vector.prototype.plus = function(other_vector) { | |
return new Vector(this.x + other_vector.x, this.y + other_vector.y); | |
}; |
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
// Flattening | |
var arrays = [[1, 2, 3], [4, 5], [6]]; | |
//arrays = arrays.concat([5000]); | |
arrays = arrays.reduce(function(prev, cur) { return prev.concat(cur); }); | |
console.log(arrays); | |
// → [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
// Sum of a Range | |
function range (start, finish, step) { | |
if (step === undefined) { | |
step = 1; | |
} | |
array = []; | |
var reverse = false; | |
step = Math.abs(step) | |
console.log(start, finish, step); | |
if (start > finish){ |
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
//Manager Class | |
import java.util.ArrayList; | |
public class Manager | |
{ | |
private ArrayList<Photographer> photographers; | |
private ArrayList<Assignment> assignments; | |
private Portfolio portfolio; | |
public Manager() { |
NewerOlder