Skip to content

Instantly share code, notes, and snippets.

// Regex Golf
verify(/ca[rt]/,
["my car", "bad cats"],
["camper", "high art"]);
verify(/pr?op/,
["pop culture", "mad props"],
["plop"]);
// 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();
}
// 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};
// 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);
};
// 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]
// 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){
@Shiggiddie
Shiggiddie / Udacity, Intro to Programming, Lesson 8: Optional Challenge
Created July 31, 2013 14:53
Classes written for Udacity Lesson 8, Optional Challenge.
//Manager Class
import java.util.ArrayList;
public class Manager
{
private ArrayList<Photographer> photographers;
private ArrayList<Assignment> assignments;
private Portfolio portfolio;
public Manager() {