VLawGz ('-' * 6)
A Pen by Captain Anonymous on CodePen.
VLawGz ('-' * 6)
A Pen by Captain Anonymous on CodePen.
class Array | |
def my_map(&nameless_fn) | |
new_arr = [] | |
return Enumerator.new(self, :my_map) unless nameless_fn | |
self.each do |x| | |
new_arr << nameless_fn.call(x) | |
end | |
new_arr | |
end |
# Challenge 3: http://www.therubygame.com/challenges/3/submissions | |
str = "The small brown & ginger fox JUMPED OVER the gate" | |
# output = "The Small Brown & Ginger Fox Jumped Over The Gate" | |
# Algorithm: | |
# 1. downcase #{str} | |
# 2. to_a | |
# 3. capitalize on each array elements | |
# 4. merge as str | |
def Capitalize(str) |
# challenge 2: http://www.therubygame.com/challenges/2 | |
gifts = "12 Drummers Drumming | |
11 Pipers Piping | |
10 Lords-a-Leaping | |
9 Ladies Dancing | |
8 Maids-a-Milking | |
7 Swans-a-Swimming | |
6 Geese-a-Laying | |
5 Gold Rings | |
4 Colly Birds |
# http://www.therubygame.com/challenges/5/submissions | |
# = 1 | |
# V = 5 | |
# X = 10 | |
# L = 50 | |
# C = 100 | |
# D = 500 | |
# M = 1000 | |
# Sample i/o: | |
# MCMXCIX gives 1999, MMXII gives 2012 |
# Puns, Palindromes and Parrots | |
# Challenge 4: http://www.therubygame.com/challenges/4/submissions | |
#str = "abacdfgdcabaypqqpy" # 324 171 163 | |
#str = "natarajan" # 81 45 42 # "ata" | |
str = "ghjiiooiijplr" | |
# desired output "ypqqpy" | |
def find_longest_palindrome(string) | |
p = "" |
# http://www.therubygame.com/challenges/6/submissions | |
module RubyChallenge | |
extend self | |
MORSE = { | |
A: '.-', B: '-...', C: '-.-.', D: '-..', E: '.', F: '..-.', G: '--.', | |
H: '....', I: '..', J: '.---', K: '-.-', L: '.-..', M: '--', N: '-.', | |
O: '---', P: '.--.', Q: '--.-', R: '.-.', S: '...', T: '-', U: '..-', |
source 'https://rubygems.org' | |
# Specify your gem's dependencies in boomboom.gemspec | |
gemspec |
# spec/spec_helper_lite.rb | |
def stub_module(full_name) | |
full_name.to_s.split(/::/).inject(Object) do |context, name| | |
begin | |
context.const_get(name) | |
rescue NameError | |
context.const_set(name, Module.new) | |
end | |
end | |
end |
// this is function definition. | |
// you can make a function take zero or more arguments (also called as parameters) | |
// This Dog fn takes one argument: 'name' | |
function Dog(name){ | |
return "hello, my name is: " + name; | |
} | |
// calling the Dog function | |
Dog('tommy'); // this will return "hello, my name is: tommy" |