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 hello = function(first, last) { | |
document.write("Hello " + first + " " + last); | |
} | |
var fav_number = function(number) { | |
if(number < 13){ | |
document.write("Little higher..."); | |
} |
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
class Book | |
attr_reader :title | |
def initialize | |
@title = " " | |
end | |
# def title=(bookname) | |
# @bookname = bookname.capitalize |
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
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 |
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
class Numeric | |
def add(num) | |
self + num | |
end | |
def subtract(num) | |
self - num | |
end | |
def multiply_by(num) |
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
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 |
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
class Integer | |
def fibonacci | |
if self == 0 | |
0 | |
elsif self < 0 | |
:invalid | |
elsif self == 1 | |
1 | |
else | |
(self - 1).fibonacci + (self - 2).fibonacci |
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
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 |
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
name = "sherief david" | |
title_name = name.gsub(/^[a-z]|\s[a-z]/) {|char| char.upcase} | |
puts title_name |