Skip to content

Instantly share code, notes, and snippets.

View Jared-Prime's full-sized avatar
📚

Jared Davis Jared-Prime

📚
View GitHub Profile
@Jared-Prime
Jared-Prime / roman_numerals.rb
Created February 28, 2012 03:04 — forked from zeroeth/roman_numerals.rb
Roman Numerals Kata
# Feb, 27th, 2012
# Kevin and Jared at Mad Railers
# run with rspec
require 'rubygems'
require 'rspec'
def roman(number)
output = ""
conversion_table = {
@Jared-Prime
Jared-Prime / gist:2371224
Created April 12, 2012 21:45
Taxi Fare - basic functions in JavaScript
// solution to Codeacademy.com project, "Taxi Fare"
// fare based upon miles traveled and the hour of the day
var taxiFare = function (milesTraveled, pickupTime) {
var baseFare = 2.50;
var costPerMile = 2.00;
var nightSurcharge = 0.50; // 8pm to 6am, every night
var cost = baseFare + (costPerMile * milesTraveled);
@Jared-Prime
Jared-Prime / gist:2371267
Created April 12, 2012 21:51
FizzBuzz++ - using nested functions
// Codeacademy.com project, "FizzBuzz++"
// Goal: count from 1 to N, and output counts, sums and averages of all numbers divisible by both 3 and 5
var FizzBuzzPlus = {
isFizzBuzzie: function(value){
if (value%3===0 && value%5===0)
return false;
else if (value%3===0 || value%5===0)
return true;
@Jared-Prime
Jared-Prime / gist:2371299
Created April 12, 2012 21:55
Olympic Tryouts - basic data validation
// Codeacademy.com project, "Olympic Tryouts"
// find the runner's average time
function calculateAverage(runnerTimes) {
var runnerTotal = 0;
for(i=0;i<runnerTimes.length;i++){
runnerTotal += runnerTimes[i];
}
var averageTime = runnerTotal / runnerTimes.length;
@Jared-Prime
Jared-Prime / fizzbuzz.js
Created April 12, 2012 21:59
FizzBuzz - fun with the modulus and loops
// Codeacademy.com project, "FizzBuzz"
// Goal: counting from 1 to 100, print "Fizz" if the numeral is divisible by 3, "Buzz" if divisible by 5, and "FizzBuzz" if divisible by both 3 and 5.
for (i=1; i<=100; i++) {
if ( i % 3 === 0 && i % 5 === 0 ) {
console.log("FizzBuzz")
}
// if the number is divisible by 3, write "Fizz"
@Jared-Prime
Jared-Prime / gist:2371354
Created April 12, 2012 22:03
Cash Register - using objects and methods
// Codeacademy.org project, "Cash Register"
// Note that you cannot change prices without changing the methods!
// A better project would ask the student to calculate the total bill using price and quantity as input.
function StaffMember(name,discountPercent){
this.name = name;
this.discountPercent = discountPercent;
}
var cashRegister = {
@Jared-Prime
Jared-Prime / gist:2371377
Created April 12, 2012 22:09
Address Book - using objects
// Codeacademy.com project, "Address Book"
// the functions input and output information about objects collected in the array.
// Note that there's no class; you have to define the attributes explicitly when creating the object.
var contacts = [];
function printPerson (person) {
console.log(person.firstName + " " + person.lastName);
}
@Jared-Prime
Jared-Prime / gist:2371404
Created April 12, 2012 22:16
Guessing Games - interactive object
// Codeacademy.com project, "Guessing Game"
// Simple interactive game, prompting the user to guess a number between 1 and 10, giving clues for the correct answer.
GuessingGame = function(min, max) {
this.init(min, max);
};
GuessingGame.prototype = {
minNumber: 1,
maxNumber: 10,
@Jared-Prime
Jared-Prime / fizz_buzz.rb
Created April 13, 2012 01:01
FizBuz - shorter & sweeter
# the classic FizzBuzz exercise, implemented with Ruby syntax
# at first, I wrote a script similar to the JavaScript exercise on Codeacademy.com
# Needless to say, the chain of if..else... statements just feels wrong.
# Below, with comments, is far superior code, modeled off http://www.rubyquiz.com/quiz126.html
# Start with an array of integers. We'll pass each integer individually to the block.
(1..100).each{ |i|
# Set an empty string as a default.
@Jared-Prime
Jared-Prime / gist:2423065
Created April 19, 2012 18:57
Converting RGB to HEX in Ruby
# Beginning Rubyists: simply run >> ruby hex-convertions.rb to see examples
# or use irb to build the code on the fly
# you can convert HEX to DEC using the method .to_i(base),
# which converts a string to a decimal number from the specified base number
puts "00".to_i(16)
puts "FF".to_i(16)