Skip to content

Commit b823583

Browse files
committed
Include Ruby exercises as sample code for session
1 parent c5a9942 commit b823583

File tree

3 files changed

+80
-0
lines changed

3 files changed

+80
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Method name: count_in_list(list, item_to_count)
2+
# Inputs: 1. a list of anything, 2. an item for us to count in the list
3+
# Returns: The number of times our item is contained in the input list
4+
# Prints: Nothing
5+
#
6+
# For example,
7+
# count_in_list([1,2,3], 1) == 1
8+
# count_in_list([1,2,3], -1) == 0
9+
# count_in_list([1,1,1], 1) == 3
10+
11+
# --- NOTE ---
12+
# Ruby has a built-in method to do this, but the purpose of this kata is
13+
# to write it yourself.
14+
#
15+
# See: http://www.ruby-doc.org/core-2.1.2/Array.html#method-i-count
16+
17+
def count_in_list(list, item_to_count)
18+
# You'll need three things:
19+
# 1. A running total of the number of times you've seen the item
20+
# 2. A way to loop/iterate through the list
21+
# 3. A way to add to the running total as you see the item
22+
end
23+
24+
if __FILE__ == $0
25+
# I'd advise putting some sanity checks here.
26+
# How else will you be sure your code does what you think it does?
27+
end
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Method name: find_links
2+
# Inputs: A website URL
3+
# Returns: An array of all link URLs on the input website
4+
# Prints: Nothing
5+
6+
require 'open-uri'
7+
require 'nokogiri'
8+
9+
# Note #1
10+
# You'll need to install the nokogiri gem if you haven't, yet. Run this
11+
# from the command line to install it:
12+
#
13+
# gem install nokogiri
14+
#
15+
# Nokogiri can be difficult to install, so if this doesn't work let us know!
16+
# The installation messages can also be intimidating, but here's Jesse
17+
# installing nokogiri on his laptop running OS X 10.9 (Mavericks)
18+
# http://cl.ly/image/163i3r290m3D
19+
20+
# Here are some tutorials on how to use Nokogiri to do this. Please email us
21+
# if you're confused about anything in the tutorials.
22+
#
23+
# http://ruby.bastardsbook.com/chapters/html-parsing/
24+
# http://lostechies.com/rodpaddock/2011/04/11/hacking-websites-with-ruby-and-nokogiri/
25+
26+
def find_links(url)
27+
# This should return an array of all links at the given URL
28+
end
29+
30+
find_links("http://www.cnn.com/").each do |url|
31+
puts url
32+
end
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Method name: longest_string(list)
2+
# Inputs: a list of strings
3+
# Returns: the longest string in the list
4+
# Prints: Nothing
5+
#
6+
# For example, longest_string(["a", "zzzz", "c"]) should return "zzzz" since
7+
# the other strings are 1 character long and "zzzz" is 4 characters long.
8+
#
9+
# To get the length of a string in the variable str, call str.length
10+
# For example,
11+
# str = "zzzz"
12+
# str.length == 4
13+
14+
def longest_string(list)
15+
# This is your job. :)
16+
end
17+
18+
if __FILE__ == $0
19+
# I'd advise putting some sanity checks here.
20+
# How else will you be sure your code does what you think it does?
21+
end

0 commit comments

Comments
 (0)