- Download this application skeleton.
- Convert the app to use AJAX.
- Add any files you changed to your gist and submit your code.
This file contains 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 count_between(array, lower_bound, upper_bound) | |
if array.empty? | |
return 0 | |
end | |
array.each do |num| | |
if num >= lower_bound && num <= upper_bound | |
return num | |
else | |
return 0 |
This file contains 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 count_between(array, lower_bound, upper_bound) | |
if array.empty? | |
return 0 | |
end | |
counter = 0 | |
array.select { |num| counter += 1 if num >= lower_bound && num <= upper_bound } | |
end | |
counter |
This file contains 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
Exercise: Calculating the array mode | |
Write a method mode which takes an Array of numbers as its input and returns an Array of the most frequent values. | |
If there's only one most-frequent value, it returns a single-element Array. | |
For example, | |
mode([1,2,3,3]) # => [3] | |
mode([4.5, 0, 0]) # => [0] | |
mode([1.5, -1, 1, 1.5]) # => [1.5] |
This file contains 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 times_table(rows) | |
if rows == 0 | |
return false | |
end | |
array = [] | |
counter = 1 | |
while counter <= rows | |
1.upto(rows) do |i| | |
array << i*counter | |
end |
This file contains 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 factorial(n) | |
if n == 0 | |
return 1 | |
end | |
counter = 0 | |
array = [] | |
while n >= counter | |
n.times do |i| | |
array << i *= (n-counter) | |
end |
This file contains 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 mode(array) | |
a = array.inject(Hash.new(0)) { |key, value| key[value] += 1; key } | |
array.sort_by { |value| a[value] }.last | |
end |
This file contains 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 GuessingGame | |
def initialize(answer) | |
@answer = answer | |
end | |
def guess(g) | |
@guess = g | |
if @answer < @guess | |
return :high | |
end |
- Download this application skeleton.
- Convert the app to use AJAX.
- Add any files you changed to your gist and submit your code.
- https://github.com/kenrett/luckyajax.git
This file contains 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
/* Here is your chance to take over Socrates! | |
Spend 10 minutes on each of the following hacks to the socrates website. | |
Enter them in the console to make sure it works and then save | |
your results here. | |
Choose a new pair for each. Add your names to the section you complete. | |
*/ |
OlderNewer