- 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
Median of an array of numbers | |
def median(array) | |
if array.length.even? | |
return (array[((array.length / 2) - 1)].to_f + array[array.length / 2].to_f) / 2 | |
else | |
return array[array.length / 2] | |
end | |
end | |
array1 = [1, 2, 3, 4, 5, 5, 7] |
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) | |
# I created a new hash to make keys out each integer. | |
b = Hash.new(0) | |
# Here, I count/tabulate each time a particular integer appears. | |
array.each do |value| | |
b[value] = b[value] + 1 | |
end | |
# b returns {-2=>1, 1=>3, 2=>3, -5=>2, 3=>1, 4=>1} with the first array |
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(guess) | |
@guess = guess | |
end | |
def guess(last_guess) # passing from last_guess = gets.chomp | |
@last_guess = last_guess | |
if @last_guess > @guess | |
return :high | |
elsif @last_guess < @guess |
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 RPNCalculator | |
def evaluate(values_and_operator) | |
@array = (values_and_operator).split(' ') | |
if @array.length == 1 | |
return @array.pop.to_i | |
end | |
while true | |
@array.each_with_index do |element, i| | |
if element == "+" |
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 9 | |
# My plain English answer: | |
# 1. Create a method for sorting the numbers in order from 1 to 10,000 (w/o the missing number). | |
# 2. Create a code block for comparing the value each successive number with its previous number. | |
# If their difference is greater than 1, then I'll subtract the previous number from the subsequent number. Then I'll add 1 to that previous number: that sum equals/is the missing number. | |
# Output the missing number. | |
# CODE... | |
def find_missing(no_order) | |
ordered_missing = no_order.sort | |
ordered_include = [*(1..10000)] |
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 choose_team(n,k) | |
return 0 if n == 0 | |
return n if k == 1 | |
choose_team(n-1, k-1) + choose_team(n-1, k) | |
end | |
p choose_team(24, 4) # pairs |
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
<!doctype html> | |
<html> | |
<head> | |
<link rel="stylesheet" href="http://cdn.jsdelivr.net/normalize/2.1.0/normalize.css"> | |
<link rel="stylesheet" href="main.css"> | |
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700,800"> | |
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Lato:100,900"> | |
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/font-awesome/3.0.2/css/font-awesome.min.css"> | |
</head> |
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
//------------------------------------------------------------------------------------------------------------------ | |
// YOUR CODE: Create your Zoo "object literal" and Animal "constructor" and "prototypes" here. | |
//------------------------------------------------------------------------------------------------------------------ | |
animals = function Animal(kind, legs) {} | |
function Zoo(animals) {} | |
Zoo.prototype.init |
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
1. They're called relational databases because the collection of tables within them are related via primary keys and foreign keys. | |
2. SQL is 'Standard (or Structured) Query Language.' It is a language used by database applications (or the SQLite file). | |
3. The two predominant views into a relational database are schema view (which shows the column names) and data view (which shows the data in each row in under the columns--and also shows the column names). | |
4. The primary key (column). | |
5. A foreign key is in the foreign key column on the table which is on the 'many' side of a 1:M relationship (relationship between two tables). It is the same as & corresponds to the primary key of the 'one side' and is used to create the relationship between the two tables. |
OlderNewer