Skip to content

Instantly share code, notes, and snippets.

@mcdonaldd
mcdonaldd / Greeter and Pig Latin
Created June 27, 2012 00:19
Javascript Week 3: Greeter and Pig Latin
var hello = function(first, last) {
document.write("Hello " + first + " " + last);
}
var fav_number = function(number) {
if(number < 13){
document.write("Little higher...");
}
@mcdonaldd
mcdonaldd / Book_Class
Created June 18, 2012 01:45
Ruby_Intro
class Book
attr_reader :title
def initialize
@title = " "
end
# def title=(bookname)
# @bookname = bookname.capitalize
@mcdonaldd
mcdonaldd / Title_Case
Created June 17, 2012 23:31
Ruby_Intro
def title_case(string)
capitalize_array = []
array = string.split
array.each do |word|
word.downcase!
first_letter = word[0].upcase!
rest_of_the_word = word[1, word.length]
new_word = first_letter << rest_of_the_word
capitalize_array << new_word
end
@mcdonaldd
mcdonaldd / Calculator
Created June 17, 2012 23:30
Ruby_Intro
class Numeric
def add(num)
self + num
end
def subtract(num)
self - num
end
def multiply_by(num)
class Fixnum
def factorial
if self < 0
raise "You can't take the factorial of a negative number."
elsif self == 0
1
else self > 0
self * (self - 1).factorial
end
end
@mcdonaldd
mcdonaldd / Fibonacci
Created June 17, 2012 23:26
Ruby_Intro
class Integer
def fibonacci
if self == 0
0
elsif self < 0
:invalid
elsif self == 1
1
else
(self - 1).fibonacci + (self - 2).fibonacci
@mcdonaldd
mcdonaldd / Pig_Latin
Created June 17, 2012 23:25
Ruby_Intro
def translate(word)
vowel = ["a", "e", "i", "o", "u"]
if vowel.include?(word[0])
word << "ay"
elsif vowel.include?(word[1])
if word[0,2] == "qu"
word << "qu"
word << "ay"
word[2,word.length]
else
@mcdonaldd
mcdonaldd / gsub
Created June 17, 2012 23:24
Ruby_Intro
name = "sherief david"
title_name = name.gsub(/^[a-z]|\s[a-z]/) {|char| char.upcase}
puts title_name